/* ==========================================================================
   Stutt Automation — Admin console stylesheet
   ========================================================================== */

:root {
  --bg: #060A12;
  --bg-2: #0A101C;
  --surface: #0E1626;
  --surface-2: #131F35;
  --surface-3: #17253F;
  --line: rgba(148, 176, 224, 0.14);
  --line-strong: rgba(148, 176, 224, 0.26);
  --text: #E9EEF9;
  --muted: #9AA8C4;
  --muted-2: #6F7E9C;
  --brand: #3D8BFF;
  --brand-2: #22D3EE;
  --amber: #F5B942;
  --green: #34D399;
  --red: #F87171;
  --grad: linear-gradient(120deg, #22D3EE 0%, #3D8BFF 100%);
  --font-head: "Sora", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.7);
  --header-h: 66px;
}

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

body {
  margin: 0;
  background:
    radial-gradient(1000px 480px at 90% -10%, rgba(61, 139, 255, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: var(--font-head); letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

::selection { background: rgba(61, 139, 255, 0.35); }

:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; border-radius: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 13px 24px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s, border-color 0.2s, opacity 0.2s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--grad); color: #04101F; box-shadow: 0 10px 28px -12px rgba(34, 211, 238, 0.55); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 32px -12px rgba(34, 211, 238, 0.65); }

.btn-ghost { background: rgba(255, 255, 255, 0.04); border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.09); }

.btn-sm { padding: 9px 18px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.btn-danger-ghost { background: transparent; border-color: rgba(248, 113, 113, 0.45); color: var(--red); }
.btn-danger-ghost:hover { background: rgba(248, 113, 113, 0.12); border-color: var(--red); }

.btn-spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(4, 16, 31, 0.3);
  border-top-color: #04101F;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brand-mark { width: 34px; height: 34px; flex: none; }

/* ------------------------------- fields --------------------------------- */

.field { display: flex; flex-direction: column; margin-bottom: 16px; }

.field label {
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

.field input, .field select, .field textarea {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.field textarea { resize: vertical; line-height: 1.55; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted-2); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(61, 139, 255, 0.18);
  background: var(--surface-2);
}

.auth-error { color: var(--red); font-size: 0.87rem; min-height: 1.2em; margin: 0 0 12px; }

/* ------------------------------ auth screen ----------------------------- */

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(700px 400px at 15% 20%, rgba(34, 211, 238, 0.08), transparent 60%),
    radial-gradient(800px 500px at 85% 90%, rgba(61, 139, 255, 0.10), transparent 60%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 38px 34px 30px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--grad);
}

.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 28px; }
.auth-brand .brand-mark { width: 42px; height: 42px; }
.auth-brand strong { display: block; font-family: var(--font-head); font-size: 1.05rem; }
.auth-brand span { font-size: 0.8rem; color: var(--brand-2); letter-spacing: 0.14em; text-transform: uppercase; }

.auth-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.auth-sub { color: var(--muted); font-size: 0.92rem; margin-bottom: 24px; }

.auth-back {
  display: block;
  text-align: center;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--muted-2);
  transition: color 0.2s;
}
.auth-back:hover { color: var(--brand-2); }

/* ------------------------------ app header ------------------------------ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(6, 10, 18, 0.85);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--line);
}

.app-header-inner {
  width: min(1280px, calc(100% - 40px));
  margin-inline: auto;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.app-brand { display: flex; align-items: center; gap: 11px; font-family: var(--font-head); font-size: 1.02rem; }
.app-brand strong { color: var(--brand-2); }

.env-chip {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
  border: 1px solid rgba(245, 185, 66, 0.4);
  background: rgba(245, 185, 66, 0.08);
  padding: 4px 10px;
  border-radius: 999px;
}

.app-actions { display: flex; align-items: center; gap: 12px; }

.app-user {
  font-size: 0.86rem;
  color: var(--muted);
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.app-user::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 8px;
  vertical-align: 1px;
}

/* -------------------------------- main ---------------------------------- */

.app-main {
  width: min(1280px, calc(100% - 40px));
  margin: 28px auto 60px;
}

/* stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--grad);
}
.stat-card.stat-new::before { background: linear-gradient(#F5B942, #F59E0B); }
.stat-card.stat-active::before { background: linear-gradient(#22D3EE, #3D8BFF); }
.stat-card.stat-won::before { background: linear-gradient(#34D399, #10B981); }

.stat-label { font-size: 0.74rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted-2); }
.stat-value { font-family: var(--font-head); font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; }
.stat-hint { font-size: 0.8rem; color: var(--muted); }
.stat-new .stat-value { color: var(--amber); }
.stat-won .stat-value { color: var(--green); }

/* panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 22px;
}

.toolbar { padding: 18px 20px; }

.toolbar-row {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search {
  position: relative;
  flex: 1 1 320px;
  max-width: 480px;
}
.search svg {
  position: absolute;
  left: 15px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted-2);
  pointer-events: none;
}
.search input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.94rem;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 12px 18px 12px 42px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(61, 139, 255, 0.16);
}
.search input::placeholder { color: var(--muted-2); }

.toolbar-buttons { display: flex; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 9px; }

.chip {
  font-family: var(--font-head);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover { color: var(--text); border-color: rgba(148, 176, 224, 0.5); }
.chip.active {
  background: var(--grad);
  border-color: transparent;
  color: #04101F;
}
.chip-unread::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--amber);
  margin-right: 7px;
  vertical-align: 1px;
}

/* table */
.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }

.quote-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.quote-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 16, 28, 0.6);
}

.quote-table td {
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.92rem;
}

.quote-table tbody tr { cursor: pointer; transition: background 0.15s; }
.quote-table tbody tr:hover { background: rgba(61, 139, 255, 0.07); }
.quote-table tbody tr:last-child td { border-bottom: 0; }

.cell-contact strong { display: block; font-size: 0.95rem; }
.cell-contact span { color: var(--muted); font-size: 0.83rem; }
.cell-contact .unread-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--amber);
  margin-right: 8px;
  vertical-align: 1px;
  box-shadow: 0 0 8px rgba(245, 185, 66, 0.7);
}
.row-muted td { opacity: 0.72; }
.cell-date span { color: var(--muted); font-size: 0.82rem; display: block; }
.cell-service { color: var(--muted); max-width: 220px; }
.cell-budget { font-family: var(--font-head); font-size: 0.85rem; }
.cell-open { text-align: right; color: var(--brand-2); font-size: 1.1rem; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-head);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.status-new { color: #F5B942; border-color: rgba(245, 185, 66, 0.45); background: rgba(245, 185, 66, 0.09); }
.status-contacted { color: #7DD3FC; border-color: rgba(125, 211, 252, 0.4); background: rgba(125, 211, 252, 0.08); }
.status-quoted { color: #22D3EE; border-color: rgba(34, 211, 238, 0.45); background: rgba(34, 211, 238, 0.09); }
.status-won { color: #34D399; border-color: rgba(52, 211, 153, 0.45); background: rgba(52, 211, 153, 0.09); }
.status-lost { color: #94A3B8; border-color: rgba(148, 163, 184, 0.4); background: rgba(148, 163, 184, 0.08); }

.empty-cell, .empty-state {
  text-align: center;
  color: var(--muted);
  padding: 54px 20px !important;
}
.empty-state strong { display: block; color: var(--text); font-family: var(--font-head); margin-bottom: 6px; font-size: 1.05rem; }

.table-foot {
  padding: 13px 20px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted-2);
}

/* ------------------------------- drawer --------------------------------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 12, 0.62);
  backdrop-filter: blur(3px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s;
}
.drawer-backdrop.show { opacity: 1; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
  box-shadow: -30px 0 70px -30px rgba(0, 0, 0, 0.85);
  z-index: 100;
  transform: translateX(102%);
  transition: transform 0.38s cubic-bezier(0.2, 0.8, 0.3, 1);
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px 26px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(61, 139, 255, 0.07), transparent);
}
.drawer-eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brand-2);
}
.drawer-head h2 { font-size: 1.35rem; margin: 6px 0 4px; }
.drawer-head p { font-size: 0.85rem; color: var(--muted); }

.icon-btn {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.09); }

.drawer-body { flex: 1; overflow-y: auto; padding: 22px 26px; }

.drawer-block { margin-bottom: 26px; }
.drawer-block h3 {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 12px;
}

.contact-rows { display: grid; gap: 9px; }
.contact-rows div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 0.92rem;
  padding-bottom: 9px;
  border-bottom: 1px dashed var(--line);
}
.contact-rows span { color: var(--muted-2); }
.contact-rows a { color: var(--brand-2); word-break: break-all; text-align: right; }
.contact-rows a:hover { text-decoration: underline; }
.contact-rows strong { text-align: right; }

.drawer-block blockquote {
  margin: 0;
  padding: 16px 18px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand-2);
  border-radius: 10px;
  font-size: 0.94rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.drawer-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 26px;
  border-top: 1px solid var(--line);
  background: rgba(10, 16, 28, 0.75);
}

/* -------------------------------- modal --------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: rgba(3, 6, 12, 0.68);
  backdrop-filter: blur(4px);
  padding: 20px;
}

.modal-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.modal-card h2 { font-size: 1.25rem; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 6px; }

/* -------------------------------- toast --------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 150%);
  z-index: 300;
  max-width: min(460px, calc(100vw - 40px));
  padding: 14px 22px;
  border-radius: 13px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.3s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.ok { border-color: rgba(52, 211, 153, 0.5); }
.toast.err { border-color: rgba(248, 113, 113, 0.55); }

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 1020px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .app-header-inner, .app-main { width: calc(100% - 28px); }
  .app-actions .app-user, #pwBtn { display: none; }
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .search { max-width: none; }
  .toolbar-buttons { justify-content: flex-end; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .drawer-foot { flex-direction: column-reverse; }
  .drawer-foot .btn { width: 100%; }
  .stat-value { font-size: 1.6rem; }
}
