:root {
  --primary: #0f4c81;
  --primary-dark: #0a365c;
  --primary-soft: #e7f0f8;
  --accent: #d97706;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn-soft: #fef3c7;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dce2ea;
  --text: #1e293b;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
}

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--primary);
}

.brand-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
}

.brand-sub {
  margin: 4px 0 20px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: 250px;
  background: var(--primary-dark);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 8px 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  margin-bottom: 8px;
}

.sidebar-brand h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.sidebar-brand small {
  color: rgba(255, 255, 255, 0.78);
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.nav-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  border: none;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-btn:hover { background: rgba(255, 255, 255, 0.12); }
.nav-btn.active { background: #ffffff; color: var(--primary-dark); font-weight: 700; }

.nav-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-user { font-size: 13px; color: var(--muted); }

.content {
  padding: 20px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 84px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
}

.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warn { background: var(--accent); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-sm { padding: 7px 12px; min-height: 34px; font-size: 13px; }
.btn-block { width: 100%; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.between { justify-content: space-between; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-warn { background: var(--warn-soft); color: #92400e; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 12px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); }
.alert-warn { background: var(--warn-soft); color: #92400e; }

.list-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.list-item:hover { border-color: var(--primary); }

.kv {
  display: grid;
  grid-template-columns: 165px 1fr;
  gap: 6px 12px;
  font-size: 14px;
}
.kv-k { color: var(--muted); }
.kv-v { font-weight: 600; word-break: break-word; }

.sig-canvas-wrap {
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  touch-action: none;
}

.sig-canvas {
  display: block;
  width: 100%;
  height: 200px;
  touch-action: none;
  cursor: crosshair;
}

.doc-thumb {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  cursor: zoom-in;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-box {
  background: #fff;
  border-radius: 14px;
  max-width: 900px;
  width: 100%;
  max-height: 92dvh;
  overflow: auto;
  padding: 16px;
}

.modal-box img { max-width: 100%; height: auto; display: block; margin: 0 auto; }

.toast-container {
  position: fixed;
  bottom: 76px;
  right: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: 340px;
}

.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 50;
  justify-content: space-around;
}

.mobile-nav button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.mobile-nav button.active { color: var(--primary); background: var(--primary-soft); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.rpt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.rpt-table th, .rpt-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.rpt-table th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
  position: sticky;
  top: 0;
}

.rpt-table td.num, .rpt-table th.num { text-align: right; }

.powered-footer {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.powered-footer img {
  height: 28px;
  width: auto;
  display: block;
}

@media (max-width: 820px) {
  .sidebar { display: none; }
  .mobile-nav { display: flex; }
  .content { padding: 12px; padding-bottom: 86px; }
  .kv { grid-template-columns: 125px 1fr; font-size: 13px; }
}
