/* MotoDealerHQ console styles — shared by dealer and platform consoles. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6778;
  --border: #dde2ea;
  --primary: #1f5eff;
  --primary-dark: #1648c4;
  --danger: #c62828;
  --warn: #b26a00;
  --success: #166b32;
  --info: #0d6e9e;
  --sidebar: #141a26;
  --sidebar-text: #c9d1e0;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
pre { background: #0f1420; color: #e6e9ef; padding: 1rem; border-radius: var(--radius); overflow-x: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: .5rem; top: .5rem; }
:focus-visible { outline: 3px solid #7aa2ff; outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 1rem; height: 56px; padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; font-size: .9rem; }
.topbar-right select { max-width: 200px; }
.nav-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 1.2rem; padding: .2rem .55rem; cursor: pointer; }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.link-button:hover { text-decoration: underline; }

/* Shell */
.shell { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 240px; flex: 0 0 240px; background: var(--sidebar); color: var(--sidebar-text); padding: 1rem .75rem 2rem; overflow-y: auto; }
.sidebar ul { list-style: none; margin: 0 0 1rem; padding: 0; }
.sidebar a { display: block; color: var(--sidebar-text); text-decoration: none; padding: .45rem .75rem; border-radius: 6px; font-size: .92rem; }
.sidebar a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar a[aria-current="page"] { background: var(--primary); color: #fff; }
.nav-group { text-transform: uppercase; letter-spacing: .06em; font-size: .72rem; color: #7d879a; margin: .75rem .75rem .35rem; }
.main { flex: 1; min-width: 0; padding: 1.5rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Banners & alerts */
.banner { padding: .6rem 1rem; font-size: .92rem; }
.banner-warn { background: #fff4e0; color: #6b4100; border-bottom: 1px solid #f3d29a; }
.banner-danger { background: #fdecea; color: #7a1a1a; border-bottom: 1px solid #f2b8b5; }
.banner-info { background: #e7f3fb; color: #0b4a6b; border-bottom: 1px solid #b7dbef; }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: .35rem 0 0 1.1rem; padding: 0; }
.alert-success { background: #e8f6ec; border-color: #b6e0c2; color: #145c2c; }
.alert-error { background: #fdecea; border-color: #f2b8b5; color: #7a1a1a; }
.alert-warning { background: #fff4e0; border-color: #f3d29a; color: #6b4100; }
.alert-info { background: #e7f3fb; border-color: #b7dbef; color: #0b4a6b; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid-stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.75rem; font-weight: 700; margin-top: .2rem; }
.stat .hint { color: var(--muted); font-size: .82rem; }
.stat a { text-decoration: none; color: inherit; }

/* Tables */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; font-size: .92rem; }
.table th { background: #f8f9fb; font-weight: 600; color: #3b4555; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfd; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }
.pagination { display: flex; gap: .5rem; margin-top: 1rem; align-items: center; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }

/* Forms */
form .form-row, .form-row { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .92rem; }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
input:not([type]), input[type=text], input[type=time], input[type=month], input[type=week], input[type=email], input[type=password], input[type=number], input[type=url], input[type=tel], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid #c3cad6; border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: 2px solid rgba(31, 94, 255, .2); }
.help { color: var(--muted); font-size: .84rem; margin-top: .25rem; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters > * { flex: 0 1 auto; }
.filters input, .filters select { width: auto; min-width: 140px; }
fieldset { min-width: 0; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .35rem; }
.perm-grid { display: grid; gap: .25rem 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .95rem; border-radius: 6px; border: 1px solid #c3cad6; background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f2f4f8; color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a31f1f; color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Badges */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 600; background: #e9edf3; color: #3b4555; white-space: nowrap; }
.badge-success, .badge-active, .badge-verified, .badge-available, .badge-won, .badge-done { background: #e3f4e8; color: #145c2c; }
.badge-warn, .badge-trial, .badge-pending, .badge-past_due, .badge-queued, .badge-running { background: #fff1d6; color: #6b4100; }
.badge-danger, .badge-suspended, .badge-failed, .badge-dead, .badge-lost, .badge-disabled { background: #fde3e1; color: #7a1a1a; }
.badge-info, .badge-new, .badge-draft { background: #e2f0fa; color: #0b4a6b; }
.badge-muted, .badge-archived, .badge-cancelled, .badge-sold { background: #eceef2; color: #555f70; }

/* Kanban */
.board { position: relative; display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.board-col { flex: 0 0 270px; background: #eaedf2; border-radius: var(--radius); padding: .75rem; min-height: 200px; }
.board-col h3 { font-size: .9rem; display: flex; justify-content: space-between; margin-bottom: .6rem; }
.board-card { background: #fff; border-radius: 6px; padding: .6rem .7rem; margin-bottom: .55rem; box-shadow: var(--shadow); font-size: .9rem; }
.board-card a { text-decoration: none; font-weight: 600; }

/* Checklist / steps */
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: .45rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .6rem; align-items: center; }
.checklist li:last-child { border-bottom: 0; }
.checklist .done { color: var(--success); font-weight: 700; }
.checklist .todo { color: #9aa3b2; }
.steps { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; padding: 0; margin: 0 0 1.25rem; counter-reset: step; }
.steps li { font-size: .8rem; padding: .25rem .6rem; border-radius: 999px; background: #e9edf3; color: var(--muted); }
.steps li.current { background: var(--primary); color: #fff; }
.steps li.complete { background: #e3f4e8; color: #145c2c; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: .4rem; font-family: ui-monospace, monospace; }
.secret { font-family: ui-monospace, monospace; font-size: 1.1rem; letter-spacing: .08em; word-break: break-all; background: #f3f5f9; padding: .5rem .75rem; border-radius: 6px; }

/* Auth pages */
.auth-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, #141a26 0%, #253150 100%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 12px; padding: 2rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.auth-card h1 { font-size: 1.4rem; }
.auth-card .btn { width: 100%; justify-content: center; }
.auth-card .links { margin-top: 1rem; font-size: .9rem; display: flex; justify-content: space-between; }

/* Error page */
.error-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.error-box { text-align: center; max-width: 520px; }
.error-code { font-size: 4rem; font-weight: 800; margin: 0; color: #6b7280; }
.debug { text-align: left; font-size: .75rem; max-height: 50vh; }

/* Marketing pages: see marketing.css */

/* Responsive */
@media (max-width: 900px) {
  .nav-toggle { display: inline-block; }
  .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0, 0, 0, .3); }
  .main { padding: 1rem; }
  .topbar-right > span, .topbar-right > a:not(:last-of-type) { display: none; }
  .topbar { gap: .75rem; }
  .topbar .brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-right { gap: .75rem; min-width: 0; flex-shrink: 0; }
  .topbar-right a, .topbar-right .link-button { white-space: nowrap; }
  .topbar-right > a:last-of-type { max-width: 6rem; overflow: hidden; text-overflow: ellipsis; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .sidebar, .topbar, .banner { display: none; } }

/* Narrow-screen safety net: wide tables scroll inside their own box; long tokens wrap. */
.card-head { flex-wrap: wrap; gap: .5rem; }
code { overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .main table:not(.table-wrap table) { display: block; position: relative; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
/* Stat tiles: label on top, figure below (some templates use <strong> rather than .value). */
a.stat { display: block; text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--primary); }
.stat > strong { display: block; font-size: 1.75rem; font-weight: 700; margin-top: .2rem; color: var(--text); }
/* Uniform control height so labels and fields line up across a filter row. */
.filters input:not([type=checkbox]):not([type=radio]):not([type=file]), .filters select,
.crm-filters input:not([type=checkbox]):not([type=radio]), .crm-filters select { height: 2.5rem; box-sizing: border-box; }
/* Wide blocks inside a form grid take the full row. */
.form-grid > fieldset, .form-grid > .table-wrap, .form-grid > table, .form-grid > p, .form-grid > h2, .form-grid > h3 { grid-column: 1 / -1; }

/* Support ticket conversation */
.ticket-thread { display: flex; flex-direction: column; gap: .6rem; }
.ticket-msg { max-width: 85%; padding: .55rem .75rem; border-radius: 10px; border: 1px solid #d0d5dd; }
.ticket-msg p { margin: .2rem 0; overflow-wrap: anywhere; }
.ticket-in { align-self: flex-start; background: #f2f4f7; }
.ticket-out { align-self: flex-end; background: #eaf1ff; border-color: #c9dafd; }
