*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #1e3a5f;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bg: #f1f5f9;
  --card-bg: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
}

body {
  font-family: 'Pretendard Variable', Pretendard, 'Malgun Gothic', '맑은 고딕', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────── */
#app { display: flex; height: 100vh; }

/* 로그인 화면 중앙정렬 — auth-gate 의 _show()가 인라인 display 를 비우므로 CSS로 보장 */
#login-screen { display: flex; align-items: center; justify-content: center; }

/* ── Sidebar ──────────────────────────────────── */
#sidebar {
  width: 210px;
  min-width: 210px;
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo        { font-size: 22px; font-weight: 800; color: #fff; letter-spacing: 2px; }
.company-name { font-size: 11px; color: #94a3b8; margin-top: 3px; }

.nav-menu    { list-style: none; padding: 10px 0; flex: 1; }
.nav-item    {
  padding: 11px 18px;
  cursor: pointer;
  font-size: 13px;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover  { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(37,99,235,0.22); border-left-color: var(--accent); color: #fff; font-weight: 600; }
.nav-icon        { font-size: 14px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 12px 18px;
  font-size: 11px;
  color: #475569;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ── Main ─────────────────────────────────────── */
#main-content { flex: 1; overflow: auto; }
.page         { display: none; padding: 28px 30px; min-height: 100%; }
.page.active  { display: block; }

/* ── Page Header ──────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  margin: -28px -30px 0;
  padding: 18px 30px 14px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 { font-size: 20px; font-weight: 700; }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 200px;
  outline: none;
  font-family: inherit;
}
.search-input:focus { border-color: var(--accent); }

.filter-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
}

.load-status {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  min-width: 40px;
}

/* ── Buttons ──────────────────────────────────── */
.btn-primary {
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-primary:hover    { background: var(--accent-hover); }
.btn-primary.loading  { opacity: 0.7; cursor: not-allowed; }
.btn-large            { padding: 10px 28px; font-size: 14px; }

/* ── Bid Grid ─────────────────────────────────── */
.bid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(370px, 1fr));
  gap: 14px;
  align-items: start;
}

/* ── Bid Card ─────────────────────────────────── */
.bid-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.bid-card:hover { box-shadow: 0 4px 18px rgba(0,0,0,0.08); border-color: #cbd5e1; }

.bid-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* Status Badges */
.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  display: inline-block;
}
.status-badge.urgent { background: #fee2e2; color: #dc2626; }
.status-badge.soon   { background: #fff7ed; color: #c2410c; }
.status-badge.open   { background: #dcfce7; color: #15803d; }
.status-badge.closed { background: #f1f5f9; color: #94a3b8; }
.status-badge.none   { background: #f8fafc; color: #94a3b8; }

/* Star / Unsave */
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 19px;
  color: #cbd5e1;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.12s;
}
.star-btn:hover { color: #f59e0b; }
.star-btn.saved { color: #f59e0b; }

.unsave-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: #cbd5e1;
  padding: 2px 6px;
  transition: color 0.12s;
}
.unsave-btn:hover { color: #ef4444; }

/* Card Content */
.bid-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 10px;
}
.bid-title a { color: var(--text); text-decoration: none; }
.bid-title a:hover { color: var(--accent); }

.bid-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 10px;
}
.meta-item { font-size: 12px; color: var(--muted); }

.bid-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
  gap: 8px;
  flex-wrap: wrap;
}
.bid-footer strong { color: var(--text); }

.method-tag {
  background: #eff6ff;
  color: var(--accent);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

/* ── Settings ─────────────────────────────────── */
.settings-container { max-width: 580px; }

.settings-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 24px;
  margin-bottom: 14px;
}
.settings-section h2 { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 14px; line-height: 1.6; }

.keyword-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; min-height: 30px; }

.keyword-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eff6ff;
  color: var(--accent);
  border: 1px solid #bfdbfe;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
}
.kw-del {
  background: none;
  border: none;
  color: #93c5fd;
  cursor: pointer;
  font-size: 15px;
  padding: 0 0 0 3px;
  line-height: 1;
  font-family: inherit;
}
.kw-del:hover { color: #ef4444; }

.keyword-add { display: flex; gap: 8px; }
.keyword-add input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.keyword-add input:focus { border-color: var(--accent); }

.radio-group { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-group label { font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 6px; }

.settings-save { margin-top: 4px; }

/* ── Empty / Error / Loading states ──────────── */
.empty, .loading-msg, .error-msg {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
}
.error-msg {
  color: #b91c1c;
  background: #fef2f2;
  border-radius: 10px;
  border: 1px solid #fecaca;
  padding: 28px 24px;
}
.error-msg small { display: block; margin-top: 8px; font-size: 12px; color: #94a3b8; }

/* ── Toast ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 9999;
  pointer-events: none;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Sidebar: toggle / groups / account / drawer (groundup식, 다크 테마) ── */
.sidebar-header { position: relative; }
#sidebar-toggle { position:absolute; top:16px; right:12px; background:transparent; border:none; color:#94a3b8; font-size:16px; cursor:pointer; padding:2px 6px; border-radius:6px; line-height:1; }
#sidebar-toggle:hover { background:rgba(255,255,255,0.08); color:#fff; }

.nav-group { list-style:none; font-size:10.5px; font-weight:700; letter-spacing:.04em; color:#64748b; padding:13px 18px 4px; text-transform:uppercase; display:flex; align-items:center; justify-content:space-between; cursor:pointer; user-select:none; }
.nav-group:hover { color:#94a3b8; }
.nav-group.nav-group-settings { margin-top:auto; }
.nav-caret { font-size:11px; transition:transform .15s; }
.nav-group.collapsed .nav-caret { transform:rotate(-90deg); }

.sidebar-footer { position: relative; }
#account-area { position:relative; margin-top:8px; }
#account-menu { position:absolute; bottom:calc(100% + 6px); left:0; right:0; background:#fff; border:1px solid var(--border); border-radius:10px; box-shadow:0 10px 30px rgba(0,0,0,0.25); padding:6px; z-index:60; }
#account-menu.hidden { display:none; }
#account-menu button { width:100%; display:flex; align-items:center; gap:9px; padding:8px 10px; border:none; background:transparent; border-radius:6px; cursor:pointer; font-size:13px; color:var(--text); text-align:left; }
#account-menu button:hover { background:#f1f5f9; }
#account-menu button span { width:16px; text-align:center; }
#account-btn { width:100%; display:flex; align-items:center; gap:9px; padding:7px 8px; border:1px solid transparent; background:transparent; border-radius:8px; cursor:pointer; text-align:left; color:#e2e8f0; }
#account-btn:hover { background:rgba(255,255,255,0.06); }
.acct-avatar { width:28px; height:28px; border-radius:50%; background:var(--accent); color:#fff; display:flex; align-items:center; justify-content:center; font-size:13px; font-weight:700; flex-shrink:0; }
.acct-meta { flex:1; min-width:0; line-height:1.25; }
.acct-meta b { font-size:12.5px; display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:#f1f5f9; }
.acct-meta > span { font-size:11px; color:#94a3b8; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block; }
.acct-caret { color:#64748b; font-size:11px; flex-shrink:0; }
.data-freshness { font-size:11px; color:#94a3b8; line-height:1.45; }

/* 접기(데스크톱 전용) */
@media (min-width: 769px) {
  #sidebar { transition: width .18s ease, min-width .18s ease; }
  #sidebar.collapsed { width:62px; min-width:62px; }
  #sidebar.collapsed .logo, #sidebar.collapsed .company-name { display:none; }
  #sidebar.collapsed .sidebar-header { padding:12px 8px; }
  #sidebar.collapsed #sidebar-toggle { right:50%; transform:translateX(50%); top:12px; }
  #sidebar.collapsed .nav-menu { padding:10px 6px; }
  #sidebar.collapsed .nav-item { font-size:0; justify-content:center; gap:0; padding:10px 0; }
  #sidebar.collapsed .nav-icon { font-size:16px; }
  #sidebar.collapsed .nav-group { font-size:0; padding:0; height:1px; margin:7px 8px; background:rgba(255,255,255,0.1); pointer-events:none; }
  #sidebar.collapsed .nav-caret { display:none; }
  #sidebar.collapsed .sidebar-footer { padding:12px 6px; }
  #sidebar.collapsed .data-freshness, #sidebar.collapsed .acct-meta, #sidebar.collapsed .acct-caret { display:none; }
  #sidebar.collapsed #account-btn { justify-content:center; }
}

/* 모바일 드로어 */
#mobile-menu-btn { display:none; }
#sidebar-backdrop { display:none; }
@media (max-width: 768px) {
  #sidebar-toggle { display:none; }
  #sidebar { position:fixed; top:0; left:0; bottom:0; z-index:70; transform:translateX(-100%); transition:transform .2s ease; }
  #sidebar.open { transform:translateX(0); }
  #sidebar-backdrop { display:block; position:fixed; inset:0; background:rgba(0,0,0,0.4); opacity:0; pointer-events:none; transition:opacity .2s; z-index:65; }
  #sidebar-backdrop.show { opacity:1; pointer-events:auto; }
  #mobile-menu-btn { display:flex; align-items:center; justify-content:center; position:fixed; top:12px; left:12px; z-index:60; width:40px; height:40px; border:1px solid var(--border); background:#fff; border-radius:8px; font-size:18px; cursor:pointer; box-shadow:0 2px 8px rgba(0,0,0,0.08); }
  .page { padding-top:60px; }
}

/* ── Detail button on card ────────────────────── */
.detail-btn { background:var(--accent); color:#fff; border:none; border-radius:6px; padding:4px 10px; font-size:12px; cursor:pointer; }
.detail-btn:hover { background:var(--accent-hover); }

/* ── Modal ────────────────────────────────────── */
.modal-overlay { position:fixed; inset:0; z-index:10000; background:rgba(15,23,42,.5); display:flex; align-items:center; justify-content:center; padding:20px; }
.modal-box { background:#fff; border-radius:14px; width:min(760px,96vw); max-height:90vh; overflow:auto; padding:28px 30px; position:relative; box-shadow:0 20px 60px rgba(0,0,0,.3); }
.modal-close { position:absolute; top:14px; right:16px; border:none; background:transparent; font-size:26px; line-height:1; color:#94a3b8; cursor:pointer; }
.modal-close:hover { color:#334155; }
.detail-title { font-size:18px; color:var(--sidebar-bg); margin-bottom:16px; padding-right:24px; }

/* ── Detail table ─────────────────────────────── */
.detail-table { width:100%; border-collapse:collapse; font-size:13.5px; }
.detail-table th { text-align:left; width:150px; color:var(--muted); font-weight:600; vertical-align:top; padding:10px 12px; border-bottom:1px solid var(--border); background:#f8fafc; }
.detail-table td { padding:10px 12px; border-bottom:1px solid var(--border); color:var(--text); }
.detail-table .muted, .muted { color:var(--muted); font-size:12px; }
.yn { display:inline-block; padding:1px 8px; border-radius:10px; font-size:12px; font-weight:600; }
.yn.yes { background:#dcfce7; color:#16a34a; }
.yn.no  { background:#fee2e2; color:#dc2626; }
.file-list { display:flex; flex-direction:column; gap:6px; }
.file-link { color:var(--accent); text-decoration:none; font-size:13px; }
.file-link:hover { text-decoration:underline; }

.detail-actions { display:flex; gap:10px; margin-top:18px; flex-wrap:wrap; }
.btn-secondary { background:#eff6ff; color:var(--accent); border:1px solid var(--accent); border-radius:8px; padding:9px 14px; font-size:13px; font-weight:600; cursor:pointer; }
.btn-secondary:hover { background:#dbeafe; }
.detail-actions .btn-primary { display:inline-flex; align-items:center; text-decoration:none; padding:9px 14px; border-radius:8px; }

/* ── Awards / previous-bid matching ───────────── */
.awards-result { margin-top:18px; }
.awards-head { font-size:13px; font-weight:700; color:var(--sidebar-bg); margin:14px 0 8px; }
.match-section { border:1px solid var(--border); border-radius:10px; padding:14px 16px; margin-bottom:14px; }
.match-section.confirmed { background:#f0fdf4; border-color:#bbf7d0; }
.match-row { display:flex; align-items:center; gap:10px; padding:8px 0; border-bottom:1px dashed var(--border); font-size:13px; }
.match-row:last-child { border-bottom:none; }
.match-row .m-main { flex:1; min-width:0; }
.match-row .m-name { font-weight:600; color:var(--text); overflow:hidden; text-overflow:ellipsis; }
.match-row .m-sub { color:var(--muted); font-size:12px; margin-top:2px; }
.match-row .m-sim { font-size:11px; color:#fff; background:#64748b; border-radius:8px; padding:1px 7px; white-space:nowrap; }
.match-row .m-sim.high { background:#16a34a; } .match-row .m-sim.mid { background:#f59e0b; }
.match-row .m-year { font-weight:700; color:var(--sidebar-bg); width:52px; text-align:center; }
.m-confirm, .m-remove { border:none; border-radius:6px; padding:5px 10px; font-size:12px; font-weight:600; cursor:pointer; white-space:nowrap; }
.m-confirm { background:var(--accent); color:#fff; } .m-confirm:hover { background:var(--accent-hover); }
.m-remove { background:#fee2e2; color:#dc2626; } .m-remove:hover { background:#fecaca; }
.match-empty { color:var(--muted); font-size:13px; padding:10px 0; }

/* ── Bid Table (데이터베이스 형태 목록) ───────────── */
.bid-table { grid-column: 1 / -1; width: 100%; border-collapse: collapse; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 13px; }
.bid-table thead th { text-align: left; padding: 10px 12px; background: #f8fafc; color: var(--muted);
  font-size: 12px; font-weight: 700; border-bottom: 2px solid var(--border); white-space: nowrap;
  position: sticky; top: var(--hh, 92px); z-index: 10; }
.bid-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.bid-table tbody tr:hover { background: #f8fafc; }
.bid-table .c-star { width: 40px; text-align: center; }
.bid-table .c-status { width: 84px; white-space: nowrap; }
.bid-table .c-money { width: 104px; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.bid-table .c-date { width: 100px; white-space: nowrap; color: var(--muted); }
.bid-table .c-close { color: #dc2626; font-weight: 600; }
.bid-table .c-link { width: 92px; white-space: nowrap; }
.bid-table .c-agency { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bid-table .c-name { color: var(--text); font-weight: 500; }
.bid-table tbody tr.bid-row { cursor: pointer; }
.bid-table tbody tr.bid-row:hover .c-name { color: var(--accent); }
.bid-table .star-btn { font-size: 16px; padding: 0; }
.g2b-link { color: var(--accent); text-decoration: none; font-size: 12px; white-space: nowrap; }
.g2b-link:hover { text-decoration: underline; }

/* 페이지 부제 */
.page-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* 테이블 정렬 헤더 */
.bid-table th.sortable { cursor: pointer; user-select: none; }
.bid-table th.sortable:hover { color: var(--text); background: #eef2f7; }
.bid-table th.sorted { color: var(--accent); }
.sort-ind { font-size: 9px; margin-left: 3px; vertical-align: middle; }

/* 기간 버튼 그룹 */
.period-group { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.period-btn { border: none; background: #fff; color: var(--muted); font-size: 12px; padding: 7px 10px; cursor: pointer; border-right: 1px solid var(--border); font-family: inherit; white-space: nowrap; }
.period-btn:last-child { border-right: none; }
.period-btn:hover { background: #f1f5f9; }
.period-btn.active { background: var(--accent); color: #fff; }
/* 툴바 요소 많음 → 검색창 폭 축소 */
.header-actions .search-input { width: 150px; }
