:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e3e8ef;
  --text: #1a2332;
  --muted: #64748b;
  --primary: #2456e6;
  --primary-hover: #1c46c2;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0.25rem 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }

.container { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

/* ---- Nav ---- */
.topnav { background: #101a33; color: #fff; }
.nav-inner {
  max-width: 1150px; margin: 0 auto; padding: 0.6rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}
.brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: var(--primary); border-radius: 6px; padding: 0.15rem 0.4rem;
  font-size: 0.8rem; letter-spacing: 0.5px;
}
.brand-mark-lg { font-size: 1.3rem; padding: 0.35rem 0.7rem; }
.nav-links { display: flex; align-items: center; gap: 1.1rem; }
.nav-links a { color: #cdd6ea; }
.nav-links a.btn { color: #fff; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 0.9rem; }
.nav-name { color: #cdd6ea; font-size: 0.88rem; }
.nav-user a { color: #8fa0c2; font-size: 0.88rem; }

/* ---- Cards & layout ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.table-card { padding: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap;
}

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #fafbfd; }
tbody tr:last-child td { border-bottom: none; }
.row-link { cursor: pointer; }
.row-link:hover { background: #f1f5fb; }
.row-urgent { box-shadow: inset 3px 0 0 #dc2626; }

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: 0.14rem 0.55rem; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-amber  { background: #fef3c7; color: #b45309; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-green  { background: #d1fae5; color: #047857; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #e5e7eb; color: #4b5563; }

/* ---- Tabs / filters ---- */
.tabs { display: inline-flex; gap: 0.25rem; margin-bottom: 1rem; background: #e9edf3; border-radius: 8px; padding: 0.2rem; }
.tab { padding: 0.3rem 0.9rem; border-radius: 6px; color: var(--muted); font-size: 0.9rem; }
.tab:hover { text-decoration: none; }
.tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.filter-bar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.filter-bar .tabs { margin-bottom: 1rem; }
.filter-bar select { margin-bottom: 1rem; width: auto; min-width: 170px; margin-top: 0; }
.filter-bar .search-input { width: auto; min-width: 240px; margin: 0 0 1rem; }
.filter-bar .btn, .filter-bar a.small { margin-bottom: 1rem; }
.stat-active { border-color: var(--primary); outline: 2px solid rgba(36, 86, 230, 0.2); }

/* ---- Stats ---- */
.stat-row { display: flex; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem 1.4rem; display: flex; flex-direction: column; min-width: 130px;
}
.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-red { color: #dc2626; }
.stat-blue { color: var(--primary); }
.stat-label { color: var(--muted); font-size: 0.82rem; }

/* ---- Forms ---- */
label { display: block; font-size: 0.86rem; font-weight: 600; margin-bottom: 0.75rem; }
input, select, textarea {
  width: 100%; padding: 0.5rem 0.65rem; margin-top: 0.25rem;
  border: 1px solid var(--border); border-radius: 7px; font: inherit; font-weight: 400;
  background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(36, 86, 230, 0.25); border-color: var(--primary);
}
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .span-2 { grid-column: span 1; } }
.form-actions { margin-top: 1.25rem; display: flex; gap: 0.75rem; }
.form-card h2 { margin-top: 1.25rem; }
.form-card h2:first-child { margin-top: 0; }
.check-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; margin: 0.5rem 0; }
.check-label input { width: auto; margin: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; padding: 0.5rem 1.05rem; border-radius: 7px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.btn:hover { background: #f1f5fb; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.84rem; }
.btn-block { width: 100%; }

/* ---- Flash messages ---- */
.flash { padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.92rem; }
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ---- Login ---- */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2.2rem; width: 380px; }
.login-card h1 { text-align: center; margin-bottom: 0.15rem; }
.login-brand { text-align: center; margin-bottom: 0.75rem; }
.login-card form { margin-top: 1.5rem; }

/* ---- Order detail ---- */
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1.25rem; margin: 0; }
.detail-list dt { color: var(--muted); font-size: 0.85rem; }
.detail-list dd { margin: 0; font-size: 0.92rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 0.45rem 0; border-bottom: 1px dashed var(--border); display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.timeline li:last-child { border-bottom: none; }

.pipeline { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 1rem; }
.pipe-step {
  font-size: 0.74rem; padding: 0.18rem 0.55rem; border-radius: 999px;
  background: #eef1f6; color: var(--muted); border: 1px solid var(--border);
}
.pipe-step.done { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; font-weight: 600; }

.tracking-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0; }

.note { border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.9rem; margin-bottom: 0.75rem; }
.note p { margin: 0.3rem 0 0; }
.note-head { display: flex; align-items: center; gap: 0.6rem; }
.note-internal { background: #fffbeb; border-color: #fde68a; }

.type-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 1.25rem; }
@media (max-width: 720px) { .type-picker { grid-template-columns: 1fr; } }
.type-option input { position: absolute; opacity: 0; width: 0; }
.type-option { margin: 0; position: relative; }
.type-box {
  display: flex; flex-direction: column; gap: 0.2rem; height: 100%;
  border: 2px solid var(--border); border-radius: 10px; padding: 0.8rem 0.9rem; cursor: pointer;
}
.type-option input:checked + .type-box { border-color: var(--primary); background: #f0f5ff; }

.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-state .btn { margin-top: 0.5rem; }

.type-picker-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .form-grid-3 { grid-template-columns: 1fr; } }

.stat-link { text-decoration: none; color: inherit; }
.stat-link:hover { text-decoration: none; border-color: var(--primary); }

.user-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: flex; gap: 0.4rem; align-items: center; margin: 0; }
.inline-form input { margin-top: 0; width: auto; }

.flag-details summary { cursor: pointer; }
.flag-form { display: flex; gap: 0.4rem; margin-top: 0.4rem; }
.flag-form input { margin-top: 0; min-width: 160px; }

/* ---- Team & permissions ---- */
.member-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.1rem; overflow: hidden; background: var(--surface); }
.member-head {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.8rem 1.1rem; background: #fafbfd; border-bottom: 1px solid var(--border);
}
.member-name { font-weight: 700; font-size: 0.98rem; }
.member-email { color: var(--muted); font-size: 0.85rem; margin-left: auto; }
.member-body { padding: 1rem 1.1rem; }
.member-foot {
  display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center;
  padding: 0.7rem 1.1rem; border-top: 1px solid var(--border); background: #fafbfd;
}

.admin-toggle {
  display: flex; align-items: flex-start; gap: 0.7rem;
  border: 1px solid var(--border); border-radius: 9px; padding: 0.75rem 0.9rem;
  margin: 0 0 0.8rem; font-weight: 400; cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.admin-toggle.on { background: #f5f3ff; border-color: #c4b5fd; }
.admin-toggle input { width: auto; margin: 0.2rem 0 0; accent-color: #6d28d9; }

.perm-grid { display: grid; grid-template-columns: 1fr; gap: 0.6rem; }
.perm-grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .perm-grid-2 { grid-template-columns: 1fr; } }
.perm-option {
  display: flex; align-items: flex-start; gap: 0.7rem;
  border: 1px solid var(--border); border-radius: 9px; padding: 0.75rem 0.9rem;
  margin: 0; font-weight: 400; cursor: pointer; transition: opacity 0.15s;
}
.perm-option input { width: auto; margin: 0.2rem 0 0; }
.perm-option.locked { opacity: 0.55; pointer-events: none; background: #f8fafc; }
.perm-title { display: block; font-weight: 600; font-size: 0.9rem; }
.perm-desc { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.1rem; line-height: 1.35; }
.perm-save { margin-top: 0.9rem; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.admin-note { font-size: 0.82rem; color: #6d28d9; }

/* Collapsible member tiles */
details.member-card > summary { list-style: none; cursor: pointer; }
details.member-card > summary::-webkit-details-marker { display: none; }
details.member-card > summary .member-head { border-bottom: none; }
details.member-card[open] > summary .member-head { border-bottom: 1px solid var(--border); }
.member-chevron { color: var(--muted); font-size: 0.75rem; transition: transform 0.15s; margin-left: 0.25rem; }
details.member-card[open] .member-chevron { transform: rotate(90deg); }
.member-perms-summary { color: var(--muted); font-size: 0.82rem; }
details.member-card > summary:hover .member-head { background: #f1f5fb; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 26, 51, 0.5);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh 1rem; z-index: 100; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal { width: 560px; max-width: 100%; margin: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.modal-head h2 { margin: 0; }
.modal-close {
  border: none; background: none; font-size: 1.4rem; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0.2rem 0.4rem; border-radius: 6px;
}
.modal-close:hover { background: #f1f5fb; color: var(--text); }
