:root {
  /* 진인해운(QIN IN SHIPPING) CI 컬러 */
  --primary: #3d4f92;       /* CI 네이비 */
  --primary-dark: #2b3a70;  /* 진한 네이비 (헤더 배경/hover) */
  --accent: #db4136;        /* CI 레드 (로고 링 컬러, 주요 버튼) */
  --accent-dark: #b93226;   /* 진한 레드 (hover) */
  --border: #dde2e8;
  --bg: #f5f7fa;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #d64545;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: #fff;
  border-bottom: 3px solid var(--primary);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.topbar .brand { display: flex; align-items: center; text-decoration: none; }
.topbar .brand img { height: 42px; width: auto; display: block; }

.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 1.4rem;
  padding: 0.3rem 0.1rem;
  border-bottom: 2px solid transparent;
  font-size: 0.92rem;
  font-weight: 600;
}

.topbar nav a.active,
.topbar nav a:hover {
  color: var(--primary);
  border-bottom-color: var(--accent);
}

.container {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1.5rem 3rem;
}

h1 { font-size: 1.4rem; margin-bottom: 1rem; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.page-head-actions { display: flex; gap: 0.6rem; }

.btn {
  display: inline-block;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-disabled { pointer-events: none; opacity: 0.4; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}
.pagination-links { display: flex; align-items: center; gap: 0.7rem; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

/* 정기 항차 템플릿의 서비스(항로 그룹) 탭 — 선택된 탭만 강조 표시 */
.service-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
/* 탭을 하나 누르기 전에는 목록을 아예 숨겨둔다 */
.service-row { display: none; }

/* 정기 항차 템플릿 목록의 "비고" 칸이 길어지면 가로 스크롤 대신 줄바꿈되도록 폭을 제한한다 */
.templates-table th:nth-child(6),
.templates-table td:nth-child(6) {
  max-width: 260px;
  white-space: normal;
  word-break: break-word;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  padding: 0.9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.filter-bar label { font-size: 0.8rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.2rem; }

.filter-date-range { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }

select, input[type="text"], input[type="date"], input[type="datetime-local"],
input[type="number"], input[type="time"], input[type="month"], textarea {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.9rem;
  font-family: inherit;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  white-space: nowrap;
}

.data-table th {
  background: #eef2f7;
  color: var(--muted);
  font-weight: 600;
}

.data-table .empty { text-align: center; color: var(--muted); padding: 2rem; }

.customers-table th { text-align: center; }
.customers-table td:nth-child(2),
.customers-table td:nth-child(4) {
  text-align: center;
}
.customers-table td.actions { justify-content: center; }

.actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.actions a { color: var(--primary); text-decoration: none; font-size: 0.85rem; }

/* 정기 항차 템플릿 목록: 헤더 셀·내용 셀 모두 가운데 정렬 */
.templates-table th {
  text-align: center;
}
.templates-table td {
  text-align: center;
}
.templates-table td.actions {
  justify-content: center;
}

/* 항차 관리 목록: 헤더 셀 전체와 관리 컬럼(수정/이력/공지메일/취소)을 가운데 정렬 */
.voyage-list-table th {
  text-align: center;
}
.voyage-list-table td.actions {
  text-align: center;
  justify-content: center;
  gap: 0.4rem;
}
/* 삭제 폼을 상세/수정/이력/공지메일과 같은 줄에 나란히 놓는다. */
.voyage-list-table td.actions .inline-delete-form {
  display: inline-flex;
}

/* 컬럼이 많아 셀 안쪽 여백을 살짝 줄여 전체 너비를 확보한다. */
.voyage-list-table th,
.voyage-list-table td {
  padding: 0.5rem 0.45rem;
}

/* 항차번호는 줄바꿈 없이 짧게, 선박 컬럼만 줄바꿈을 허용해 너비를 줄인다.
   나머지는 관리 컬럼(취소 버튼)이 가로 스크롤 없이 보이도록 컴팩트하게 맞춘다. */
.voyage-list-table th:nth-child(1),
.voyage-list-table td:nth-child(1) {
  white-space: nowrap;
  text-align: center;
}
.voyage-list-table th:nth-child(2),
.voyage-list-table td:nth-child(2) {
  min-width: 130px;
  max-width: 150px;
  white-space: normal;
  word-break: break-word;
}

.inline-delete-form { display: flex; gap: 0.25rem; align-items: center; }

.badge {
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: #9ca3af;
}
.badge-예정 { background: #6b7280; }
.badge-확정 { background: #1a8a4a; }
.badge-변경 { background: #d68d1a; }
.badge-취소 { background: #b0343f; }
.badge-trade-수출 { background: var(--primary); }
.badge-trade-수입 { background: #7a3fc4; }
.badge-op-용선 { background: #1a8a4a; }
.badge-op-타선 { background: #6b7280; }
.badge-warn { background: var(--danger); margin-left: 0.3rem; }

.table-scroll { overflow-x: auto; }

.form-wide { max-width: 760px; }

.form-section {
  font-size: 0.95rem;
  color: var(--primary-dark);
  margin: 0.4rem 0 -0.2rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}
.form-section:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
}
@media (max-width: 800px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .grid-3 { grid-template-columns: 1fr; }
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
}
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .grid-4 { grid-template-columns: 1fr; }
}

.form {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* 항차/템플릿 등록·수정 화면처럼 필드가 많은 폼: 세로로만 쌓으면 스크롤이 길어져서,
   한눈에 볼 수 있게 가로 폭을 넓히고 위의 .grid-2/.grid-3/.grid-4 안에 필드를 나눠 담는다. */
.form-xl { max-width: 1180px; }

/* 라벨 줄바꿈 여부가 칸마다 달라도(1줄/2줄), 같은 줄에 있는 입력칸끼리는 높이를 맞춰
   아래쪽에 나란히 붙인다 — 그리드가 칸 높이를 그 줄의 제일 긴 라벨에 맞춰 늘려주는 걸 이용. */
.field { display: flex; flex-direction: column; justify-content: space-between; gap: 0.3rem; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.hint { font-size: 0.78rem; color: var(--muted); margin: 0 0 0.8rem; }
#reason-field.required-hint textarea { border-color: var(--danger); }
#reason-field.required-hint > label::after { content: " (필수)"; color: var(--danger); font-weight: 400; }
#change-reason-group { display: flex; flex-direction: column; gap: 0.3rem; }
#terminal-group { display: flex; flex-direction: column; gap: 0.3rem; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 0.4rem; }

.alert { padding: 0.7rem 0.9rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fdecec; color: var(--danger); border: 1px solid #f4c4c4; }
.alert-success { background: #e9f7ef; color: #1a8a4a; border: 1px solid #b9e6cb; }

.summary { color: var(--muted); margin-bottom: 1rem; }

.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.2rem;
}
.panel-title { font-size: 1rem; margin: 0 0 0.7rem; }

.inline-form { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: flex-end; }
.inline-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }

.checkbox-label { display: flex !important; flex-direction: row !important; align-items: center; gap: 0.4rem; font-weight: 400 !important; }
/* 화주 이메일이 길거나 여러 개(콤마 나열)라 공백 없이 이어져도 화면 밖으로 넘어가지 않고
   줄바꿈되도록 한다. (flex 안의 텍스트는 기본적으로 줄어들지 않아 넘칠 수 있어 min-width:0 필요) */
.notify-row-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
/* 화주 검색 필터로 숨기는 행. .checkbox-label의 display:flex !important 때문에
   자바스크립트로 style.display = 'none'을 줘도 무시되고 계속 보이는 문제가 있어,
   더 나중에 선언된(=우선순위가 앞서는) !important 클래스로 확실히 숨긴다. */
.notify-row-hidden { display: none !important; }
/* 발송 대상 화주 표를 10명씩 페이지로 나눠 보여줄 때, 지금 페이지가 아닌 행을 숨긴다. */
.notify-page-hidden { display: none !important; }

/* 항로 지도 */
.port-label {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  padding: 0.1rem 0.4rem;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text);
}

.ais-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}
.ais-card { margin-bottom: 0; display: flex; flex-direction: column; gap: 0.6rem; }

/* 캘린더 뷰 */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}
.cal-nav-title { font-size: 1.15rem; font-weight: 700; min-width: 8rem; text-align: center; }

.cal-legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 0.7rem; font-size: 0.82rem; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.3rem; }

.calendar-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  table-layout: fixed;
}
.calendar-table th {
  background: #eef2f7;
  color: var(--muted);
  font-weight: 600;
  padding: 0.5rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.cal-sun { color: #b0343f; }
.cal-sat { color: var(--primary); }

.cal-cell {
  vertical-align: top;
  border: 1px solid var(--border);
  padding: 0.35rem;
  height: 6.5rem;
  width: 14.28%;
  overflow: hidden;
}
.cal-empty { background: #fafbfc; }
.cal-past { background: #fbf4f4; }
.cal-daynum { font-size: 0.82rem; font-weight: 700; color: var(--muted); margin-bottom: 0.25rem; }

.cal-event {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.badge-mini { padding: 0.05rem 0.35rem; font-size: 0.65rem; margin-left: auto; }

@media (max-width: 700px) {
  .calendar-table, .calendar-table thead, .calendar-table tbody, .calendar-table th, .calendar-table td, .calendar-table tr { display: block; }
  .cal-cell { width: 100%; height: auto; }
}

/* 메인 화면 */
.hero {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1.5rem;
  min-height: 260px;
  display: flex;
  align-items: flex-end;
}
.hero img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
.hero-overlay {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 1.5rem 1.8rem;
  background: linear-gradient(0deg, rgba(15, 23, 42, 0.88) 0%, rgba(15, 23, 42, 0.55) 55%, rgba(15, 23, 42, 0.05) 100%);
  color: #fff;
}
.hero-brand { font-size: 0.85rem; letter-spacing: 0.06em; color: #cfd8f0; font-weight: 600; margin-bottom: 0.3rem; }
.hero-title { font-size: 1.6rem; font-weight: 800; margin: 0 0 0.4rem; color: #fff; }
.hero-sub { font-size: 0.92rem; color: #e4e8f5; margin: 0 0 1rem; }

.nav-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.nav-tile {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, transform 0.15s;
}
.nav-tile:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08); transform: translateY(-2px); border-color: var(--primary); }
.nav-tile-icon { font-size: 1.6rem; margin-bottom: 0.4rem; }
.nav-tile-title { font-weight: 700; margin-bottom: 0.2rem; }
.nav-tile-desc { font-size: 0.82rem; color: var(--muted); }
