/* PowerSell - application stylesheet.
   Single sheet, no build step, no CDN. Colour and spacing come from the tokens below so the
   board, the CRM pages and the admin screens stay visually consistent. */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 2px 8px rgba(15, 23, 42, .08);
    --shadow-lg: 0 8px 24px rgba(15, 23, 42, .12);

    --sidebar-width: 232px;
    --topbar-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.011em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ---- Application shell ---------------------------------------------------------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: #0f172a;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.02em;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-brand .logo {
    width: 26px; height: 26px;
    border-radius: 7px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: grid; place-items: center;
    font-size: 13px; font-weight: 800; color: #fff;
}

.sidebar-nav { padding: 10px 8px; flex: 1; }

.nav-heading {
    padding: 14px 10px 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: #64748b;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    font-weight: 500;
    margin-bottom: 1px;
}

.nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .ico { width: 17px; text-align: center; font-size: 14px; opacity: .9; }

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, .08);
    padding: 12px;
}

.user-chip { display: flex; align-items: center; gap: 9px; }
.user-chip .meta { min-width: 0; flex: 1; }
.user-chip .name { color: #fff; font-weight: 600; font-size: 13px; }
.user-chip .role { font-size: 11px; color: #64748b; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar h1 { flex: 1; }
.topbar-sub { color: var(--text-muted); font-size: 12px; font-weight: 400; }

.content { padding: 20px; flex: 1; }
.content.flush { padding: 0; display: flex; flex-direction: column; min-height: 0; }

/* ---- Live indicator ------------------------------------------------------------------- */

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 4px 9px;
    border-radius: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.live-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-faint);
    transition: background .2s;
}

.live-badge[data-state="live"] .live-dot { background: var(--success); animation: pulse 2s infinite; }
.live-badge[data-state="live"] { color: var(--success); border-color: #bbf7d0; background: var(--success-soft); }
.live-badge[data-state="down"] .live-dot { background: var(--danger); }
.live-badge[data-state="down"] { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

/* ---- Buttons -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}

.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Cards, panels, tables ------------------------------------------------------------ */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.panel-header {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-header h2 { flex: 1; }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.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)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3, .grid-sidebar { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
    .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
    text-align: left;
    padding: 9px 14px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ---- Forms ---------------------------------------------------------------------------- */

label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=search], input[type=url],
select, textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

textarea { resize: vertical; min-height: 78px; line-height: 1.55; }
input[type=color] { width: 44px; height: 32px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }

.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; min-width: 0; }
.field-hint { font-size: 11px; color: var(--text-faint); margin-top: 4px; font-weight: 400; }

.checkbox { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.checkbox input { width: auto; margin-top: 2px; flex: 0 0 auto; }
.checkbox label { margin: 0; font-weight: 500; color: var(--text); font-size: 13px; }

fieldset { border: none; padding: 0; margin: 0 0 22px; }
legend {
    font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-muted); padding: 0 0 10px; width: 100%;
    border-bottom: 1px solid var(--border); margin-bottom: 14px;
}

.form-actions { display: flex; gap: 9px; padding-top: 6px; }
.inline-form { display: inline; }

/* ---- Badges, avatars, misc ------------------------------------------------------------ */

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
    background: var(--surface-2); color: var(--text-muted);
    border: 1px solid var(--border);
}

.badge-primary { background: var(--primary-soft); color: var(--primary-dark); border-color: #bfdbfe; }
.badge-success { background: var(--success-soft); color: #15803d; border-color: #bbf7d0; }
.badge-warning { background: var(--warning-soft); color: #b45309; border-color: #fde68a; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; border-color: #fecaca; }

.avatar {
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    color: #fff; font-size: 10.5px; font-weight: 700;
    flex: 0 0 auto; letter-spacing: .02em;
}
.avatar-sm { width: 21px; height: 21px; font-size: 9px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 3px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

.empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty .icon { font-size: 30px; opacity: .35; margin-bottom: 10px; }

/* ---- Flash messages ------------------------------------------------------------------- */

.alert {
    padding: 11px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid;
    display: flex; align-items: flex-start; gap: 9px;
}
.alert-success { background: var(--success-soft); border-color: #bbf7d0; color: #15803d; }
.alert-error { background: var(--danger-soft); border-color: #fecaca; color: #b91c1c; }
.alert-info { background: var(--primary-soft); border-color: #bfdbfe; color: var(--primary-dark); }

/* ---- Toasts (live updates) ------------------------------------------------------------ */

#toasts {
    position: fixed; bottom: 18px; right: 18px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px;
    max-width: 330px;
}

.toast {
    background: #0f172a;
    color: #f8fafc;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    animation: toast-in .22s ease-out;
    display: flex; align-items: center; gap: 9px;
}
.toast.leaving { animation: toast-out .22s ease-in forwards; }
.toast .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex: 0 0 auto; }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }

/* ---- Kanban board --------------------------------------------------------------------- */

.board-toolbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.board-stat { display: flex; flex-direction: column; line-height: 1.25; }
.board-stat .label { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 700; }
.board-stat .value { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

.board {
    flex: 1;
    display: flex;
    gap: 12px;
    padding: 16px 20px 20px;
    overflow-x: auto;
    align-items: flex-start;
    min-height: 0;
}

.column {
    flex: 0 0 292px;
    width: 292px;
    background: #e9edf3;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--topbar-height) - 106px);
    border: 1px solid var(--border);
}

.column.drop-target { background: #dbeafe; border-color: var(--primary); }
.column.over-wip .column-count { background: var(--danger); color: #fff; }

.column-header {
    padding: 10px 12px 8px;
    border-bottom: 1px solid rgba(15, 23, 42, .07);
    cursor: grab;
}
.column-header:active { cursor: grabbing; }
.column.stage-dragging { opacity: .4; }

.column-title { display: flex; align-items: center; gap: 7px; }
.column-swatch { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }
.column-name { font-weight: 700; font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.column-count {
    background: rgba(15, 23, 42, .09);
    border-radius: 20px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.column-meta {
    display: flex; gap: 10px; margin-top: 5px;
    font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums;
}

.column-cards {
    padding: 8px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-height: 56px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 10px 11px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    cursor: grab;
    display: block;
    color: inherit;
    transition: box-shadow .12s, transform .12s;
}

.card:hover { box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: .38; }
.card.just-updated { animation: flash 1.4s ease-out; }

@keyframes flash {
    0% { box-shadow: 0 0 0 2px var(--primary); background: var(--primary-soft); }
    100% { box-shadow: var(--shadow-sm); background: var(--surface); }
}

.card-title { font-weight: 600; font-size: 13px; margin-bottom: 3px; line-height: 1.35; }
.card-company { font-size: 11.5px; color: var(--text-muted); margin-bottom: 7px; }

.card-footer { display: flex; align-items: center; gap: 6px; }
.card-value { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.card-flags { display: flex; gap: 4px; margin-top: 7px; flex-wrap: wrap; }

.card-drop-line {
    height: 2px;
    background: var(--primary);
    border-radius: 2px;
    margin: 1px 0;
}

.priority-bar { width: 3px; border-radius: 2px; align-self: stretch; }
.priority-LOW { background: #cbd5e1; }
.priority-MEDIUM { background: #60a5fa; }
.priority-HIGH { background: var(--warning); }
.priority-CRITICAL { background: var(--danger); }

.column-add {
    padding: 7px 10px;
    margin: 0 8px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    text-align: center;
    border: 1px dashed var(--border-strong);
}
.column-add:hover { background: rgba(255, 255, 255, .7); color: var(--text); text-decoration: none; }

/* ---- Dashboard ------------------------------------------------------------------------ */

.metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    box-shadow: var(--shadow-sm);
}

.metric .label {
    font-size: 10.5px; font-weight: 700; letter-spacing: .07em;
    text-transform: uppercase; color: var(--text-faint); margin-bottom: 7px;
}
.metric .value { font-size: 25px; font-weight: 700; letter-spacing: -.025em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.metric .sub { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 9px; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }
.progress-bar.over { background: var(--success); }

.funnel-row { display: flex; align-items: center; gap: 11px; padding: 8px 0; }
.funnel-label { width: 128px; flex: 0 0 128px; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel-track { flex: 1; height: 22px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 4px; min-width: 2px; transition: width .3s; }
.funnel-value { width: 128px; flex: 0 0 128px; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; }

.chart { display: flex; align-items: flex-end; gap: 9px; height: 148px; padding-top: 10px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 3px; transition: height .3s; }
.chart-bar:hover { background: var(--primary-dark); }
.chart-label { font-size: 10.5px; color: var(--text-muted); font-weight: 600; }
.chart-value { font-size: 10.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---- Timeline ------------------------------------------------------------------------- */

.timeline { position: relative; padding-left: 26px; }
.timeline::before {
    content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px;
    width: 2px; background: var(--border);
}

.timeline-item { position: relative; padding: 0 0 18px; }
.timeline-item::before {
    content: ''; position: absolute; left: -22px; top: 5px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--border-strong);
}
.timeline-item.positive::before { border-color: var(--success); }
.timeline-item.negative::before { border-color: var(--danger); }
.timeline-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.timeline-body { font-size: 13px; color: var(--text-muted); margin-top: 4px; white-space: pre-wrap; }

/* ---- Login ---------------------------------------------------------------------------- */

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #1e293b, #0f172a 60%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 372px;
    background: var(--surface);
    border-radius: 14px;
    padding: 30px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .3);
}

.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
.login-brand .logo {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.login-brand .name { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }

.login-hint {
    margin-top: 18px; padding: 11px 13px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 12px; color: var(--text-muted);
}
.login-hint code { font-family: var(--mono); color: var(--text); font-size: 11.5px; }

/* ---- Permission editor ---------------------------------------------------------------- */

.perm-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.perm-group-head {
    padding: 9px 14px; background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.perm-group-head h3 { flex: 1; font-size: 13px; }
.perm-list { padding: 12px 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 20px; }
@media (max-width: 900px) { .perm-list { grid-template-columns: minmax(0, 1fr); } }
.perm-code { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
    padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
