:root {
  --navy: #123b6d;
  --navy-2: #0b2b50;
  --blue: #1e5b99;
  --red: #e33a2c;
  --ink: #1c2735;
  --muted: #68778a;
  --bg: #f4f7fb;
  --card: #ffffff;
  --line: #dbe4ef;
  --line-strong: #c8d5e4;
  --success: #177c52;
  --warning: #a76a00;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(18, 59, 109, .10);
  --radius: 16px;
  --sidebar: 258px;
}
* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* Login */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.2fr); background: #fff; }
.login-panel { padding: clamp(32px, 6vw, 88px); display: flex; flex-direction: column; justify-content: center; }
.login-hero { background: linear-gradient(145deg, #0b2b50, #123b6d 55%, #1b568f); color: #fff; padding: clamp(38px, 7vw, 96px); display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.login-hero::before, .login-hero::after { content: ""; position: absolute; border-radius: 999px; background: rgba(255,255,255,.08); }
.login-hero::before { width: 340px; height: 340px; right: -120px; top: -80px; }
.login-hero::after { width: 220px; height: 220px; left: -80px; bottom: -80px; }
.login-logo { width: 260px; max-width: 100%; margin-bottom: 24px; }
.login-title { font-size: clamp(34px, 5vw, 58px); line-height: 1.02; margin: 0 0 20px; letter-spacing: -.03em; }
.login-copy { font-size: 18px; line-height: 1.6; max-width: 620px; color: rgba(255,255,255,.84); }
.login-list { display: grid; gap: 12px; margin-top: 24px; }
.login-list div { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.9); }
.login-list span { width: 26px; height: 26px; display: inline-grid; place-items: center; border-radius: 8px; background: rgba(255,255,255,.14); }

/* App shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) 1fr; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--navy-2); color: #fff; padding: 22px 16px; display: flex; flex-direction: column; z-index: 40; }
.sidebar-logo { background: #fff; border-radius: 14px; padding: 8px 10px; margin: 0 4px 26px; }
.sidebar-logo img { width: 100%; display: block; }
.nav { display: grid; gap: 7px; }
.nav button { border: 0; background: transparent; color: rgba(255,255,255,.72); display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 13px; border-radius: 12px; text-align: left; font-weight: 650; }
.nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav button.active { background: #fff; color: var(--navy); }
.nav-icon { width: 23px; height: 23px; display: grid; place-items: center; font-size: 17px; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 2px; color: rgba(255,255,255,.72); font-size: 13px; }
.sidebar-user { padding-top: 12px; margin-top: 12px; border-top: 1px solid rgba(255,255,255,.12); display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-weight: 800; }
.main { grid-column: 2; min-width: 0; }
.topbar { height: 72px; background: rgba(255,255,255,.94); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.mobile-menu { display: none; border: 0; background: #eef3f8; width: 42px; height: 42px; border-radius: 12px; }
.topbar-title { font-size: 19px; font-weight: 800; color: var(--navy); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 28px; max-width: 1600px; margin: 0 auto; }

/* Shared */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 0 0 6px; color: var(--navy); font-size: clamp(27px, 4vw, 38px); letter-spacing: -.025em; }
.page-head p { margin: 0; color: var(--muted); line-height: 1.55; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { border: 1px solid transparent; border-radius: 11px; padding: 10px 15px; font-weight: 750; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--line-strong); }
.btn-secondary:hover { background: #f8fbff; }
.btn-danger { background: #fff; border-color: #f3c5c1; color: var(--danger); }
.btn-success { background: var(--success); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-small { min-height: 34px; padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn-icon { width: 42px; padding: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgba(18,59,109,.05); }
.card-pad { padding: 22px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { padding: 20px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; width: 74px; height: 74px; border-radius: 50%; right: -18px; top: -18px; background: #eef4fa; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 34px; font-weight: 850; color: var(--navy); margin-top: 6px; letter-spacing: -.03em; }
.stat-note { margin-top: 7px; font-size: 13px; color: var(--muted); }
.section-title { margin: 0 0 14px; font-size: 18px; color: var(--navy); }
.kicker { color: var(--red); font-size: 12px; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--navy); font-size: 18px; margin-bottom: 8px; }
.notice { padding: 14px 16px; border-radius: 12px; background: #eef6ff; border: 1px solid #cfe2f7; color: #244b73; line-height: 1.5; }
.notice.warn { background: #fff7e8; border-color: #f1d59b; color: #805300; }
.notice.danger { background: #fff1f0; border-color: #f3c6c1; color: #8d2118; }

/* Tables & filters */
.toolbar { padding: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.search { position: relative; flex: 1 1 280px; }
.search input { padding-left: 38px; }
.search::before { content: "⌕"; position: absolute; left: 13px; top: 50%; transform: translateY(-52%); color: var(--muted); font-size: 20px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 13px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); }
td { padding: 15px 16px; border-bottom: 1px solid #edf1f5; vertical-align: middle; }
tbody tr:hover { background: #fbfdff; }
tbody tr:last-child td { border-bottom: 0; }
.row-title { font-weight: 800; color: var(--navy); }
.row-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-draft { color: #64748b; background: #eef2f7; }
.badge-sent { color: #2c60a0; background: #eaf2ff; }
.badge-filled { color: #7a4bb2; background: #f2ebff; }
.badge-signed { color: #177c52; background: #e5f6ee; }
.badge-closed { color: #0f556a; background: #e2f4f8; }
.badge-cancelled { color: #a13a34; background: #fdecea; }
.badge-overdue { color: #a75b00; background: #fff0d6; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }

/* Forms */
.form-card { padding: 22px; margin-bottom: 18px; }
.form-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.form-section-head h2 { margin: 0; font-size: 18px; color: var(--navy); }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: 14px; }
.field { grid-column: span 4; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
.field.span-4 { grid-column: span 4; }
.field.span-5 { grid-column: span 5; }
.field.span-6 { grid-column: span 6; }
.field.span-8 { grid-column: span 8; }
.field.span-9 { grid-column: span 9; }
.field.span-12 { grid-column: span 12; }
label { display: block; color: #3c4b5d; font-size: 13px; font-weight: 750; margin-bottom: 7px; }
input, select, textarea { width: 100%; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); border-radius: 10px; padding: 10px 12px; min-height: 42px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: #72a4d4; box-shadow: 0 0 0 3px rgba(30,91,153,.12); }
textarea { min-height: 92px; resize: vertical; }
.check-grid { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.check { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-weight: 650; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--navy); }
.help { color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 5px; }
.contract-client-card { border-color: #cfe2f7; }
.compact-form { gap: 12px; }
.form-details { border: 1px solid var(--line); border-radius: 12px; background: #f8fbff; overflow: hidden; }
.form-details summary { cursor: pointer; padding: 13px 14px; color: var(--navy); font-weight: 850; list-style: none; }
.form-details summary::-webkit-details-marker { display: none; }
.form-details summary::after { content: "+"; float: right; color: var(--red); font-weight: 900; }
.form-details[open] summary { border-bottom: 1px solid var(--line); background: #eef6ff; }
.form-details[open] summary::after { content: "-"; }
.details-grid { padding: 14px; }
.sticky-actions { position: sticky; bottom: 12px; z-index: 20; display: flex; justify-content: space-between; gap: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); box-shadow: var(--shadow); margin-top: 18px; }
.signature-box { border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; overflow: hidden; }
.signature-box canvas { width: 100%; height: 150px; display: block; touch-action: none; background: linear-gradient(#fff,#fff), repeating-linear-gradient(0deg,transparent,transparent 24px,#f1f4f8 25px); }
.signature-actions { display: flex; justify-content: space-between; padding: 8px 10px; background: #f8fafc; border-top: 1px solid var(--line); }

/* Detail */
.detail-grid { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(320px,.7fr); gap: 18px; }
.detail-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px 18px; }
.detail-item { padding-bottom: 11px; border-bottom: 1px dashed var(--line); }
.detail-item span { color: var(--muted); font-size: 12px; display: block; margin-bottom: 4px; }
.detail-item strong { font-size: 14px; }
.timeline { display: grid; gap: 14px; }
.timeline-item { display: grid; grid-template-columns: 13px 1fr; gap: 10px; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--navy); margin-top: 5px; box-shadow: 0 0 0 4px #e7eff8; }
.timeline-title { font-weight: 750; }
.timeline-time { color: var(--muted); font-size: 12px; margin-top: 3px; }
.share-box { border: 1px dashed #9db9d8; background: #f7fbff; border-radius: 12px; padding: 14px; }
.share-url { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; background: #fff; border: 1px solid var(--line); padding: 10px; border-radius: 9px; margin: 10px 0; }
.license-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.license-gallery.compact { margin-top: 12px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.license-thumb { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; text-decoration: none; display: grid; }
.license-thumb img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #eef3f8; display: block; }
.license-thumb span { padding: 8px 10px; font-size: 12px; color: var(--navy); font-weight: 750; overflow-wrap: anywhere; }

/* Public portal */
.public-shell { min-height: 100vh; background: linear-gradient(180deg, #edf4fb 0, #f7f9fc 280px); padding: 26px 14px 60px; }
.public-wrap { max-width: 980px; margin: 0 auto; }
.public-head { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 18px; }
.public-head img { width: 230px; max-width: 44%; }
.public-title { text-align: right; }
.public-title h1 { margin: 0; color: var(--navy); font-size: 24px; }
.public-title p { margin: 5px 0 0; color: var(--muted); }
.summary-strip { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px; margin-bottom: 18px; }
.summary-chip { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 13px; }
.summary-chip span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.summary-chip strong { display: block; margin-top: 5px; color: var(--navy); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(7,24,45,.58); display: grid; place-items: center; z-index: 100; padding: 18px; }
.modal { background: #fff; width: min(620px,100%); max-height: 88vh; overflow: auto; border-radius: 18px; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; color: var(--navy); font-size: 20px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* Toast */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 200; }
.toast { background: #102f55; color: #fff; min-width: 260px; max-width: 420px; padding: 13px 15px; border-radius: 12px; box-shadow: 0 14px 34px rgba(0,0,0,.2); animation: toastIn .2s ease-out; }
.toast.error { background: #8d2118; }
.toast.success { background: #176b4c; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

/* Print */
@media print {
  .sidebar, .topbar, .no-print, #toast-root { display: none !important; }
  .app-shell, .main { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 850px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .main { grid-column: 1; }
  .sidebar { transform: translateX(-105%); transition: transform .2s ease; box-shadow: 18px 0 50px rgba(7,24,45,.25); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; place-items: center; }
  .content { padding: 20px 14px; }
  .topbar { padding: 0 14px; }
  .page-head { flex-direction: column; }
  .form-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .field, .field.span-2, .field.span-3, .field.span-4, .field.span-5, .field.span-6, .field.span-8, .field.span-9 { grid-column: span 1; }
  .field.span-12 { grid-column: span 2; }
  .summary-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 560px) {
  .stats, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar-title { max-width: 190px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .topbar-actions .hide-mobile { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .field, .field.span-12 { grid-column: span 1; }
  .sticky-actions { flex-direction: column; }
  .sticky-actions .actions { width: 100%; }
  .sticky-actions .btn { flex: 1; }
  .public-head { align-items: flex-start; }
  .public-title h1 { font-size: 19px; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .detail-list { grid-template-columns: 1fr; }
}
