:root {
  --navy: #0b1f3a;
  --navy-2: #122a4a;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --success: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100%; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

/* Login */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1e3a5f 0%, transparent 55%),
    linear-gradient(160deg, #061225, #0b1f3a 45%, #102a4c);
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 28px; }
.login-brand h1 { margin: 0; font-size: 1.35rem; }
.tagline {
  margin: 2px 0 0;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}
.logo-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; letter-spacing: 0.02em;
}
.logo-mark.sm { width: 36px; height: 36px; font-size: 0.85rem; border-radius: 10px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.login-card input {
  display: block; width: 100%; margin-top: 6px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.login-hint { font-size: 0.75rem; color: var(--muted); margin-top: 18px; line-height: 1.4; }
.form-error { color: var(--danger); font-size: 0.85rem; margin-top: 10px; }

/* Topbar */
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  position: sticky; top: 0; z-index: 40;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.brand-title { font-weight: 700; font-size: 0.95rem; line-height: 1.1; }
.brand-sub { font-size: 0.62rem; letter-spacing: 0.14em; opacity: 0.7; font-weight: 600; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab {
  background: transparent; border: 0; color: rgba(255,255,255,.72);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 0.9rem;
}
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.active { background: rgba(59,130,246,.25); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip {
  font-size: 0.8rem; background: rgba(255,255,255,.1);
  padding: 6px 10px; border-radius: 999px; color: #e2e8f0;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px 20px 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 0.8rem; font-weight: 500; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; color: var(--navy); }

.content { padding: 16px 20px 40px; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 12px;
}
.search-wrap { flex: 1; min-width: 220px; }
.search-wrap input, .toolbar select, .toolbar input[type="search"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.toolbar select { width: auto; min-width: 150px; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th {
  text-align: left; padding: 12px 14px; background: #f8fafc;
  color: var(--muted); font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f8fbff; }
.muted { color: var(--muted); }
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; background: #e2e8f0; color: #334155;
}
.badge.active, .badge.new, .badge.lead { background: #dbeafe; color: #1d4ed8; }
.badge.inactive, .badge.closed { background: #f1f5f9; color: #64748b; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.rejected, .badge.error { background: #fee2e2; color: #991b1b; }

.btn {
  border: 0; border-radius: 8px; padding: 9px 14px; cursor: pointer;
  font-weight: 600; font-size: 0.875rem;
  background: #e2e8f0; color: var(--text);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.2); }
.topbar .btn-ghost { color: #fff; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; justify-content: flex-end; color: var(--muted); font-size: 0.85rem; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.sheet-panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: min(520px, 100%);
  background: var(--surface);
  box-shadow: -12px 0 40px rgba(0,0,0,.2);
  display: flex; flex-direction: column;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fafc, #fff);
}
.sheet-head h2 { margin: 4px 0 0; font-size: 1.25rem; }
.sheet-code { font-size: 0.75rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.sheet-body { padding: 16px 20px 40px; overflow: auto; flex: 1; }
.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px;
  margin-bottom: 20px;
}
.detail-grid .full { grid-column: 1 / -1; }
.field-label { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.field-value { margin-top: 2px; font-weight: 500; word-break: break-word; }
.section-title {
  font-size: 0.85rem; font-weight: 700; margin: 18px 0 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.note-item, .task-item, .audit-item {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; background: #fafbfc;
}
.note-meta, .audit-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.task-item { display: flex; gap: 10px; align-items: flex-start; }
.task-item.done { opacity: 0.55; text-decoration: line-through; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.inline-form input, .inline-form textarea, .modal-card input, .modal-card select, .modal-card textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; width: 100%;
}
.inline-form input { flex: 1; min-width: 120px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.5); }
.modal-card {
  position: relative; background: #fff; border-radius: 14px;
  width: min(480px, calc(100% - 32px)); padding: 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal-card h3 { margin: 0 0 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 500; margin-bottom: 4px; }

.timeline { max-width: 800px; }
.audit-item strong { font-weight: 600; }

.import-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
  max-width: 900px;
}
.import-box h2 { margin-top: 0; }
.import-warn {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  padding: 12px 14px; border-radius: 10px; margin: 12px 0 18px; font-size: 0.9rem; line-height: 1.45;
}
.import-report {
  background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px;
  overflow: auto; font-size: 0.8rem; margin-top: 14px;
}
#import-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 999px;
  z-index: 80; box-shadow: var(--shadow); font-size: 0.9rem;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; }
  .detail-grid { grid-template-columns: 1fr; }
}
