/* Base theme — brand variables come from /branding.css */
:root {
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --card: #ffffff;
  --danger: #dc2626;
  --r: var(--brand-radius, 8px);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--brand-font); color: var(--text); background: var(--brand-bg); font-size: 14px; line-height: 1.5; }
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.cap { text-transform: capitalize; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pre { white-space: pre-line; }
.upper { text-transform: uppercase; }
.r { text-align: right; }
.mt { margin-top: 12px; }
.grow { flex: 1; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex-shrink: 0; background: var(--brand-sidebar); color: var(--brand-on-sidebar); display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.sidebar a { color: inherit; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; text-decoration: none !important; }
.brand-logo { max-width: 100%; max-height: 52px; object-fit: contain; }
.brand-mark { width: 34px; height: 34px; border-radius: var(--r); background: var(--brand-accent); color: var(--brand-on-accent); display: grid; place-items: center; font-weight: 700; font-size: 17px; flex-shrink: 0; }
.brand-mark.lg { width: 56px; height: 56px; font-size: 26px; }
.brand-name { font-weight: 700; line-height: 1.2; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { padding: 9px 12px; border-radius: var(--r); opacity: .82; text-decoration: none; }
.sidebar nav a:hover { opacity: 1; background: color-mix(in srgb, currentColor 10%, transparent); }
.sidebar nav a.active { opacity: 1; background: var(--brand-primary); color: var(--brand-on-primary); }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 16px 12px 4px; }
.sidebar-foot { border-top: 1px solid color-mix(in srgb, currentColor 18%, transparent); padding-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.me { display: flex; flex-direction: column; line-height: 1.25; text-decoration: none !important; }
.me span { font-size: 12px; opacity: .65; text-transform: capitalize; }
.sidebar .link { color: inherit; opacity: .75; }
.main { flex: 1; padding: 28px 32px; min-width: 0; }
.footer { margin-top: 32px; color: var(--muted); font-size: 12px; text-align: center; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.crumbs { font-size: 12px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 560px; }
.pad { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; }
.grid-2 > .card { margin-bottom: 20px; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: var(--r); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { border-color: var(--brand-primary); }
.btn-primary { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--brand-on-primary); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-block { width: 100%; justify-content: center; padding: 11px; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-primary); cursor: pointer; }
.link:hover { text-decoration: underline; }
.danger { color: var(--danger); }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: var(--r); background: #fff; color: var(--text); width: 100%; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand-primary) 35%, transparent); border-color: var(--brand-primary); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; width: 44px; height: 36px; cursor: pointer; }
input[type=file] { padding: 6px; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }

.form-grid { display: flex; flex-direction: column; gap: 8px; }
fieldset { border: 0; padding: 0; margin: 0 0 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
legend { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: span 4; }
.form-actions { display: flex; gap: 10px; }

.flash { padding: 12px 16px; border-radius: var(--r); margin-bottom: 18px; border: 1px solid; }
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--brand-bg) 50%, #fff); white-space: nowrap; }
.table td:first-child { white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table.compact th, .table.compact td { padding: 8px 10px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot th { border-top: 2px solid var(--line); border-bottom: 0; background: none; color: var(--text); }
.row-link { cursor: pointer; }
.row-link:hover td { background: color-mix(in srgb, var(--brand-primary) 4%, #fff); }
tr.inactive td { opacity: .5; }

/* Status badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #e2e8f0; color: #334155; }
.badge.lg { font-size: 13px; padding: 3px 12px; }
.status-draft { background: #f1f5f9; color: #475569; }
.status-awaiting-documents { background: #fef3c7; color: #92400e; }
.status-submitted { background: #dbeafe; color: #1e40af; }
.status-query-raised { background: #ffedd5; color: #9a3412; }
.status-on-hold { background: #fee2e2; color: #991b1b; }
.status-cleared { background: #dcfce7; color: #166534; }
.status-cancelled { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }
.dir { font-size: 12px; font-weight: 600; }
.dir-import { color: #0369a1; }
.dir-export { color: #7c3aed; }
.dir-transit { color: #0f766e; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand-primary); border-radius: var(--r); padding: 16px 18px; display: flex; flex-direction: column; color: var(--text); text-decoration: none !important; }
.stat:nth-child(2) { border-left-color: var(--brand-accent); }
.stat-n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat-l { color: var(--muted); font-size: 13px; }
.pipeline { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px; }
.pipe { flex: 1; min-width: 110px; border-radius: var(--r); padding: 10px 12px; font-size: 12px; font-weight: 600; text-decoration: none !important; display: flex; flex-direction: column; }
.pipe span { font-size: 22px; }
.feed { list-style: none; padding: 0; margin: 0; }
.feed li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed li.is-note { background: color-mix(in srgb, var(--brand-accent) 8%, #fff); padding: 10px 12px; border-radius: var(--r); border: 0; margin: 6px 0; }
.feed-time { float: right; color: var(--muted); font-size: 12px; }

/* Clearance detail */
.status-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 14px 20px; }
.status-bar label { flex-direction: row; align-items: center; gap: 8px; }
.status-bar select { width: auto; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.note-box { margin-top: 14px; padding: 12px; background: var(--brand-bg); border-radius: var(--r); }
.estimate { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-end; margin-top: 14px; padding: 14px; background: color-mix(in srgb, var(--brand-primary) 6%, #fff); border-radius: var(--r); }
.estimate div { display: flex; flex-direction: column; }
.estimate strong { font-size: 18px; }
.estimate p { flex-basis: 100%; margin: 0; }
.add-line { margin-top: 14px; }
.add-line summary { list-style: none; }
.add-line summary::-webkit-details-marker { display: none; }
.line-form { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 12px; padding: 14px; border: 1px dashed var(--line); border-radius: var(--r); }
.align-end { display: flex; align-items: flex-end; }
.docs { list-style: none; padding: 0; margin: 0 0 14px; }
.docs li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.upload { display: flex; gap: 8px; flex-wrap: wrap; }
.upload select { width: auto; }
.upload input[type=file] { flex: 1; min-width: 180px; }
.note-form { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; }

/* Lists */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px; }
.filters input[type=search] { flex: 1; min-width: 240px; }
.filters select { width: auto; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; }
.inline-edit summary { list-style: none; cursor: pointer; }
.inline-edit[open] { position: relative; }
.inline-edit[open] form { position: absolute; right: 0; top: 24px; z-index: 5; width: 280px; background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.12); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand-sidebar) 0%, var(--brand-sidebar) 40%, var(--brand-bg) 40%); }
.login-card { background: #fff; width: 100%; max-width: 400px; padding: 36px; border-radius: calc(var(--r) * 1.5); box-shadow: 0 20px 50px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 16px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.login-brand img { max-height: 70px; max-width: 220px; object-fit: contain; }
.login-brand h1 { font-size: 20px; justify-content: center; margin: 6px 0 0; }
.login-brand p { margin: 0; }
.login-msg { margin: 0; font-weight: 600; }

/* Branding page */
.branding-layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
.branding-layout h2 { margin-top: 8px; }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.color-input { display: flex; align-items: center; gap: 10px; }
.current-img { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); background: repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.current-img img { max-height: 44px; max-width: 140px; }
.current-img.sm img { max-height: 24px; }
.sticky { position: sticky; top: 20px; }
.preview { display: flex; height: 240px; border: 1px solid var(--line); border-radius: var(--brand-radius); overflow: hidden; font-family: var(--brand-font); background: var(--brand-bg); font-size: 12px; }
.pv-side { width: 130px; background: var(--brand-sidebar); color: var(--brand-on-sidebar); padding: 12px 8px; display: flex; flex-direction: column; gap: 3px; }
.pv-brand { font-weight: 700; padding: 0 6px 10px; }
.pv-brand img { max-width: 100%; max-height: 32px; }
.pv-nav { padding: 6px 8px; border-radius: var(--brand-radius); opacity: .8; }
.pv-nav.active { background: var(--brand-primary); color: var(--brand-on-primary); opacity: 1; }
.pv-main { flex: 1; padding: 14px; }
.pv-card { background: #fff; border: 1px solid var(--line); border-radius: var(--brand-radius); padding: 12px; }
.pv-card .btn { padding: 5px 10px; font-size: 12px; border-radius: var(--brand-radius); }
.pv-card .btn-primary { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--brand-on-primary); }
.pv-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.pv-accent { background: var(--brand-accent); color: var(--brand-on-accent); }

/* Responsive */
@media (max-width: 1100px) { .branding-layout { grid-template-columns: 1fr; } .line-form { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .brand { padding-bottom: 0; }
  .nav-label { display: none; }
  .sidebar-foot { border: 0; padding: 0; margin-left: auto; }
  .main { padding: 18px; }
  fieldset { grid-template-columns: 1fr 1fr; }
  .span-4 { grid-column: span 2; }
  .grid-2 { grid-template-columns: 1fr; }
  .line-form { grid-template-columns: 1fr 1fr; }
}

/* Print a clean clearance sheet */
@media print {
  .sidebar, .no-print, .actions, .flash, .footer { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { border: 0; padding: 0 0 12px; }
}

/* licence + updates */
.flash-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; margin-left: 4px; }
.pill-on { color: #065f46; font-weight: 600; } .pill-off { color: #6b7280; }
.licbox { white-space: pre-wrap; word-break: break-all; font-family: ui-monospace, monospace; font-size: .8rem; }
