/* =========================================================================
   Wise & Jack Document System — shared design system
   One place for tokens + components. Link this on every page.
   ========================================================================= */

:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  /* Brand + accent */
  --brand-900: #0f172a;
  --brand-800: #1e293b;
  --brand-700: #334155;
  --accent:      #4f46e5;
  --accent-600:  #4338ca;
  --accent-50:   #eef2ff;
  --accent-100:  #e0e7ff;

  /* Neutrals / surfaces */
  --bg:            #e9edf3;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --border:        #e6e8ec;
  --border-strong: #d3d7de;
  --text:   #111827;
  --text-2: #374151;
  --muted:  #6b7280;
  --muted-2:#9ca3af;

  /* Status */
  --ok: #15803d;     --ok-bg: #dcfce7;
  --warn: #b45309;   --warn-bg: #fef3c7;
  --danger: #dc2626; --danger-bg: #fee2e2;
  --info: #1d4ed8;   --info-bg: #dbeafe;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow:    0 4px 14px rgba(16,24,40,.08);
  --shadow-lg: 0 16px 40px rgba(16,24,40,.16);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { margin: 0; color: var(--text); font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-100); }

/* ---------- Brand mark (small logo square) ---------- */
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .02em;
  box-shadow: var(--shadow-sm);
}
.brand-dim { color: var(--muted); font-weight: 500; }

/* ---------- App header / top bar ---------- */
.header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--brand-800); border-bottom: 1px solid var(--brand-900);
  padding: 13px 28px;
}
.header h1 {
  display: flex; align-items: center; gap: 11px;
  font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.02em;
}
.header .brand-dim { color: #9aa6bd; }
.header .brand-mark { box-shadow: 0 0 0 1px rgba(255,255,255,.14); }
.user-info { display: flex; align-items: center; gap: 14px; color: #b8c1d4; font-size: 14px; }
.user-info #userName { color: #fff; font-weight: 550; }
.header .logout-btn { background: rgba(255,255,255,.10); color: #e7ebf3; border-color: rgba(255,255,255,.22); }
.header .logout-btn:hover { background: rgba(255,255,255,.18); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 2px; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 0 20px; overflow-x: auto;
}
.tab {
  padding: 13px 15px; font-size: 14px; font-weight: 550; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Layout ---------- */
.page-head { max-width: 1200px; margin: 0 auto; padding: 18px 22px 2px; }
.page-head h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.container { max-width: 1200px; margin: 0 auto; padding: 14px 22px 22px; }
.tab-content { display: none; }
.tab-content.active { display: block; animation: wj-fade .2s ease; }
@keyframes wj-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards / sections ---------- */
.files-section, .search-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 16px;
}
.section-header, .search-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.section-header h2, .search-header h2, .section-header h3 { font-size: 16px; font-weight: 650; }

/* ---------- Stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px;
}
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--brand-800); letter-spacing: -0.02em; line-height: 1.1; }
.stat-card h3, .stat-card .label, .stat-card > div:first-child {
  color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}

/* ---------- Buttons ---------- */
button { font-family: inherit; }
.new-doc-btn, .search-btn, .modal-btn {
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, box-shadow .15s, transform .05s;
  display: inline-flex; align-items: center; gap: 7px;
}
.new-doc-btn:hover, .search-btn:hover, .modal-btn:hover { background: var(--accent-600); box-shadow: var(--shadow-sm); }
.new-doc-btn:active, .search-btn:active, .modal-btn:active { transform: translateY(1px); }

.filter-btn, .logout-btn, .modal-btn-cancel {
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border-strong);
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 550;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.filter-btn:hover, .logout-btn:hover, .modal-btn-cancel:hover { background: var(--bg); }
.filter-btn.active { background: var(--accent-50); border-color: var(--accent); color: var(--accent-600); }

/* small table-row actions */
.action-btn, .view-btn, .edit-btn, .delete-btn {
  min-width: 54px; padding: 5px 10px; border-radius: 6px; font-size: 12px; font-weight: 550; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  transition: background .15s, border-color .15s, color .15s; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.view-btn:hover, .edit-btn:hover, .action-btn:hover { border-color: var(--accent); color: var(--accent-600); background: var(--accent-50); }
.delete-btn { color: var(--danger); border-color: #f0c9c9; }
.delete-btn:hover { background: var(--danger-bg); border-color: var(--danger); }

/* Shared buttons used by the form / detail / P&S pages */
.btn-primary {
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  padding: 10px 18px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .15s, box-shadow .15s;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn-primary:hover { background: var(--accent-600); box-shadow: var(--shadow-sm); }
.btn-primary:disabled { background: var(--muted-2); border-color: var(--muted-2); cursor: not-allowed; }
.btn-secondary, .btn-cancel {
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border-strong);
  padding: 10px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 550;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn-secondary:hover, .btn-cancel:hover { background: var(--bg); border-color: var(--muted-2); }
.btn-generate {
  background: var(--accent); color: #fff; border: none; width: 100%;
  padding: 12px 18px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.btn-generate:hover { background: var(--accent-600); }
.btn-generate:disabled { background: var(--muted-2); cursor: not-allowed; }
.btn-edit { background: var(--accent); color: #fff; border: none; padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-edit:hover { background: var(--accent-600); }
.btn-delete { background: var(--surface); color: var(--danger); border: 1px solid #f0c9c9; padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-delete:hover { background: var(--danger-bg); border-color: var(--danger); }

/* Shared alerts (kept hidden/shown by each page's own display rules) */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 14px; border: 1px solid transparent; }
.alert.success { background: var(--ok-bg); color: var(--ok); border-color: #b7e4c7; }
.alert.error { background: var(--danger-bg); color: var(--danger); border-color: #f3c0c0; }
.alert.info { background: var(--info-bg); color: var(--info); border-color: #bcd3f5; }

/* Header action buttons row (form/detail pages) */
.header-actions { display: flex; gap: 12px; align-items: center; }

/* ---------- Forms / search ---------- */
.search-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
/* Single-line search bar: heading + form fields + action buttons on one row */
.search-oneline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.search-oneline > h2 { margin: 0; white-space: nowrap; }
.search-oneline .search-form { display: contents; }
.search-oneline .search-input { flex: 1 1 220px; }
.search-oneline .search-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.search-input, .search-select {
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text); min-width: 180px;
}
.search-input:focus, .search-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-100); }
.search-input::placeholder { color: var(--muted-2); }

/* ---------- Tables (rendered by JS into containers) ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 14px; color: var(--text-2); font-weight: 700;
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border-strong); background: var(--surface-2);
}
tbody td { padding: 8px 14px; border-bottom: 1px solid var(--border); color: var(--text-2); }
.cell-case { font-size: 11px; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }

/* ---------- Status badges ---------- */
.status-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.status-active   { background: var(--info-bg); color: var(--info); }
.status-pending  { background: var(--warn-bg); color: var(--warn); }
.status-completed, .status-closed { background: var(--ok-bg); color: var(--ok); }
.status-cancelled { background: #eceef1; color: var(--muted); }

/* Inline editable status dropdown (dashboard + file view) */
.status-select {
  border: 1px solid transparent; border-radius: 6px; padding: 4px 8px;
  font-size: 12px; font-weight: 600; font-family: inherit; cursor: pointer; text-transform: capitalize;
}
.status-select:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-100); }
.status-select.status-active    { background-color: var(--info-bg); color: var(--info); }
.status-select.status-pending   { background-color: var(--warn-bg); color: var(--warn); }
.status-select.status-closed,
.status-select.status-completed { background-color: var(--ok-bg); color: var(--ok); }
.status-select.status-cancelled { background-color: #eceef1; color: var(--muted); }

/* ---------- Empty / loading ---------- */
.empty-state, .loading, .no-results { text-align: center; padding: 44px 20px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal-content {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-width: 580px; width: 100%; padding: 26px;
}
.modal-header { margin-bottom: 18px; }
.modal-header h2, .modal-header h3 { font-size: 18px; }
.transaction-type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.transaction-type-option {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer;
  text-align: center; font-weight: 550; transition: border-color .15s, background .15s, box-shadow .15s;
}
.transaction-type-option:hover { border-color: var(--accent); background: var(--accent-50); box-shadow: var(--shadow-sm); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1100px 560px at 50% -20%, #eaeeff 0%, var(--bg) 55%);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 40px; max-width: 400px; width: 100%; text-align: center;
}
.login-card .brand-mark { width: 46px; height: 46px; font-size: 16px; border-radius: 12px; margin-bottom: 18px; }
.login-card .login-logo { display: block; width: 260px; max-width: 84%; height: auto; margin: 4px auto 2px; }
.login-card h1 { font-size: 22px; }
.login-card .subtitle { color: var(--muted); margin: 4px 0 26px; font-size: 14px; letter-spacing: .01em; }
.google-btn {
  width: 100%; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 11px 18px; font-size: 15px; font-weight: 600; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: background .15s, border-color .15s, box-shadow .15s; text-decoration: none;
}
.google-btn:hover { background: var(--surface-2); border-color: var(--accent); box-shadow: var(--shadow-sm); text-decoration: none; }
.google-icon { width: 18px; height: 18px; }
.login-card .info { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .header { padding: 11px 16px; }
  .header h1 { font-size: 15px; }
  .container { padding: 16px; }
  .tabs { padding: 0 8px; }
  .search-form { flex-direction: column; align-items: stretch; }
  .search-input, .search-select { min-width: 0; width: 100%; }
}

/* Table cells holding prose: show three lines, full text in the title. */
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; white-space: normal; max-width: 360px; line-height: 1.35; }
