:root {
    --color-primary: #6366f1;
    --color-primary-dark: #4f46e5;
    --color-primary-light: #eef0ff;
    --color-text: #171923;
    --color-heading: #0f1117;
    --color-muted: #6b7280;
    --color-muted-2: #9ca3af;
    --color-border: #e7e8ee;
    --color-border-strong: #d6d8e2;
    --color-bg: #f6f7fb;
    --color-surface: #ffffff;
    --color-error: #e11d48;
    --color-error-bg: #fff1f3;
    --color-success: #059669;
    --color-success-bg: #ecfdf5;

    --icon-indigo-bg: #eef0ff; --icon-indigo-fg: #6366f1;
    --icon-sky-bg:    #e8f6fd; --icon-sky-fg:    #0284c7;
    --icon-amber-bg:  #fef6e7; --icon-amber-fg:  #d97706;
    --icon-violet-bg: #f5eefe; --icon-violet-fg: #9333ea;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 20px;
    --shadow-xs: 0 1px 2px rgba(15, 17, 23, 0.05);
    --shadow-sm: 0 2px 6px rgba(15, 17, 23, 0.05);
    --shadow-md: 0 8px 24px rgba(15, 17, 23, 0.07);
    --shadow-lg: 0 20px 48px rgba(15, 17, 23, 0.14);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background:
        radial-gradient(900px 360px at 85% -8%, #eef0ff 0%, transparent 55%),
        radial-gradient(700px 320px at 5% 0%, #f0f9ff 0%, transparent 50%),
        var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
}

.icon {
    width: 18px;
    height: 18px;
    display: block;
    flex-shrink: 0;
}

/* ---- Top bar ------------------------------------------------------- */

.topbar {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-inner {
    max-width: 980px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--color-primary), #a855f7);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(99, 102, 241, 0.35);
}

.brand-text {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--color-heading);
}

.brand-accent {
    color: var(--color-primary);
}

.brand-tag {
    color: var(--color-muted);
    font-size: 0.82rem;
    font-weight: 500;
}

.top-nav {
    display: flex;
    gap: 4px;
}

.top-nav a {
    text-decoration: none;
    color: var(--color-muted);
    font-size: 0.86rem;
    font-weight: 600;
    padding: 7px 13px;
    border-radius: 999px;
    transition: background 0.15s ease, color 0.15s ease;
}

.top-nav a:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.top-nav a.is-active {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    padding-left: 12px;
    border-left: 1px solid var(--color-border);
}

.user-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--color-text);
    padding: 6px 4px;
}

.user-name .icon {
    width: 14px;
    height: 14px;
    color: var(--color-muted);
}

.logout-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--color-muted);
    transition: background 0.15s ease, color 0.15s ease;
}

.logout-link:hover {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.logout-link .icon { width: 16px; height: 16px; }

/* ---- Page layout ----------------------------------------------------- */

.page {
    max-width: 860px;
    margin: 0 auto;
    padding: 40px 20px 80px;
}

.page-wide {
    max-width: 980px;
}

.page-full {
    max-width: 1360px;
}

.page-header {
    margin-bottom: 22px;
}

.page-header h1 {
    margin: 0 0 6px;
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--color-heading);
}

.page-header .subtitle {
    margin: 0;
    color: var(--color-muted);
    font-size: 0.96rem;
}

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

/* ---- Alerts ------------------------------------------------------- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 14px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.92rem;
    font-weight: 500;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    border-left: 3px solid transparent;
    animation: alertIn 0.25s ease-out;
}

@keyframes alertIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.alert-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 1px;
}

.alert-icon .icon { width: 13px; height: 13px; }

.alert-success {
    color: #047857;
    border-left-color: var(--color-success);
}
.alert-success .alert-icon { background: var(--color-success-bg); color: var(--color-success); }

.alert-error {
    color: #be123c;
    border-left-color: var(--color-error);
}
.alert-error .alert-icon { background: var(--color-error-bg); color: var(--color-error); }

.alert-warning {
    color: var(--icon-amber-fg);
    border-left-color: var(--icon-amber-fg);
}
.alert-warning .alert-icon { background: var(--icon-amber-bg); color: var(--icon-amber-fg); }

.alert-inline {
    margin-bottom: 14px;
    box-shadow: none;
    background: var(--color-error-bg);
}

/* ---- Card / form ----------------------------------------------------- */

.card-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 6px 30px 26px;
    box-shadow: var(--shadow-lg);
    animation: cardIn 0.35s ease-out;
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .card-form, .alert { animation: none; }
}

.form-section {
    padding: 26px 0 22px;
    border-bottom: 1px solid var(--color-border);
}

.form-section-last,
.form-section:last-of-type {
    border-bottom: 0;
    padding-bottom: 4px;
}

.section-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.section-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-indigo { background: var(--icon-indigo-bg); color: var(--icon-indigo-fg); }
.icon-sky    { background: var(--icon-sky-bg);    color: var(--icon-sky-fg); }
.icon-amber  { background: var(--icon-amber-bg);  color: var(--icon-amber-fg); }
.icon-violet { background: var(--icon-violet-bg); color: var(--icon-violet-fg); }

.section-head h2 {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--color-heading);
    letter-spacing: -0.01em;
}

.section-head p {
    margin: 1px 0 0;
    font-size: 0.8rem;
    color: var(--color-muted);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
}

.field {
    display: flex;
    flex-direction: column;
    position: relative;
}

.field-full { grid-column: 1 / -1; }
.field-half { grid-column: span 1; max-width: 340px; }
.field-narrow input,
.field-narrow .input-icon { max-width: 320px; }

label {
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--color-text);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}

.hint {
    font-weight: 400;
    font-size: 0.78rem;
    color: var(--color-muted-2);
}

.req { color: var(--color-error); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
    padding: 10px 13px;
    border: 1.5px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.94rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input::placeholder,
textarea::placeholder {
    color: var(--color-muted-2);
}

input:hover, select:hover, textarea:hover {
    border-color: var(--color-border-strong);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.13);
}

textarea { resize: vertical; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%236b7280' stroke-width='1.6' fill='none' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 34px;
    cursor: pointer;
}

/* Icon-adorned inputs (phone, email, pincode search) */
.input-icon {
    position: relative;
}

.input-icon > .icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-muted-2);
    pointer-events: none;
}

.input-icon input,
.input-icon select {
    padding-left: 38px;
}

/* Compact variant used inside item rows, where columns are narrower */
.input-icon-sm > .icon {
    left: 10px;
    width: 14px;
    height: 14px;
}

.input-icon-sm input,
.input-icon-sm select {
    padding-left: 30px;
}

.error {
    margin-top: 5px;
    font-size: 0.8rem;
    color: var(--color-error);
    font-weight: 500;
}

/* Brief highlight when a field gets auto-filled */
@keyframes fieldFilled {
    0%   { background: #ecfdf5; box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.16); border-color: var(--color-success); }
    100% { background: var(--color-surface); box-shadow: none; }
}

.field-filled { animation: fieldFilled 1.15s ease-out; }

/* ---- Pincode combobox -------------------------------------------- */

.combo { position: relative; }

.combo-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 20;
    padding: 6px;
}

.combo-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.combo-option:hover,
.combo-option.is-active {
    background: var(--color-primary-light);
}

.combo-option-pin {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.82rem;
    color: var(--color-primary-dark);
    background: #fff;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--icon-indigo-bg);
}

.combo-option-detail {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 0.85rem;
}

.combo-option-detail strong {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.combo-option-detail small {
    color: var(--color-muted);
    font-size: 0.76rem;
}

.combo-empty {
    padding: 16px 14px;
    text-align: center;
    color: var(--color-muted);
    font-size: 0.85rem;
}

.combo-empty p {
    margin: 0 0 8px;
}

.combo-add-link,
.add-customer-shortcut {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--color-primary-dark);
    text-decoration: none;
}

.combo-add-link:hover,
.add-customer-shortcut:hover {
    text-decoration: underline;
}

.add-customer-shortcut {
    margin-top: 8px;
    font-size: 0.82rem;
}

.add-customer-shortcut .icon { width: 13px; height: 13px; }

.combo-footer {
    border-top: 1px solid var(--color-border);
    margin-top: 4px;
    padding: 9px 10px 4px;
    text-align: center;
}

.combo-heading {
    padding: 8px 10px 6px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted-2);
}

.combo-status {
    font-size: 0.78rem;
    color: var(--color-muted);
    margin-top: 5px;
    min-height: 1em;
}

.combo-status.is-error { color: var(--color-error); }

/* ---- Order line items ------------------------------------------------ */

.items-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
}

.item-row {
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 14px 14px;
    background: #fbfbfd;
}

.item-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.item-row-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--icon-violet-bg);
    color: var(--icon-violet-fg);
    font-size: 0.75rem;
    font-weight: 700;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.icon-btn .icon { width: 16px; height: 16px; }

.item-row-grid {
    display: grid;
    grid-template-columns: 1fr 1.6fr 0.8fr 1fr;
    gap: 10px;
}

.item-row-grid label {
    font-size: 0.72rem;
    color: var(--color-muted);
    margin-bottom: 4px;
}

.btn-ghost {
    background: var(--color-surface);
    color: var(--color-primary-dark);
    border-color: var(--icon-indigo-bg);
    border-style: dashed;
    width: 100%;
    justify-content: center;
    padding: 10px;
}

.btn-ghost:hover {
    background: var(--icon-indigo-bg);
}

.btn-ghost .icon { width: 15px; height: 15px; }

/* ---- Actions ------------------------------------------------------- */

.form-actions {
    margin-top: 26px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.required-note {
    font-size: 0.8rem;
    color: var(--color-muted);
}

.form-actions-buttons {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 11px 22px;
    border-radius: var(--radius-sm);
    font-size: 0.94rem;
    font-weight: 600;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
    color: #fff;
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.32);
}

.btn-primary:hover {
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
    filter: brightness(1.04);
}

.btn-primary .icon { width: 15px; height: 15px; }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border-strong);
}

.btn-secondary:hover { background: #f9fafb; }

@media (max-width: 760px) {
    .item-row-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .field-half { max-width: none; }
    .card-form { padding: 4px 18px 22px; }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions-buttons { justify-content: stretch; }
    .form-actions-buttons .btn { flex: 1; justify-content: center; }
    .item-row-grid { grid-template-columns: 1fr; }
}

/* ---- Auth (login) page ------------------------------------------------ */

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

.auth-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 36px 32px;
    animation: cardIn 0.35s ease-out;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 26px;
}

.brand-mark-lg {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1rem;
}

.auth-title {
    margin: 0 0 6px;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-heading);
}

.auth-subtitle {
    margin: 0 0 22px;
    color: var(--color-muted);
    font-size: 0.88rem;
}

.auth-form .field {
    margin-bottom: 16px;
}

.auth-submit {
    width: 100%;
    justify-content: center;
    margin-top: 6px;
    padding: 12px;
}

.input-icon-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--color-muted-2);
    border-radius: 6px;
    cursor: pointer;
}

.input-icon-toggle:hover {
    background: var(--color-bg);
    color: var(--color-muted);
}

.input-icon-toggle .icon { width: 16px; height: 16px; }

.auth-form .input-icon input {
    padding-right: 38px;
}

@media (max-width: 460px) {
    .auth-card { padding: 28px 22px; }
}

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

.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.dash-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 26px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.dash-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary-light);
    transform: translateY(-2px);
}

.dash-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.dash-card-icon .icon { width: 20px; height: 20px; }

.dash-card h2 {
    margin: 0 0 6px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-heading);
}

.dash-card p {
    margin: 0;
    color: var(--color-muted);
    font-size: 0.86rem;
    line-height: 1.5;
}

@media (max-width: 600px) {
    .dash-grid { grid-template-columns: 1fr; }
}

/* ---- Recent orders table ---------------------------------------------- */

.recent-orders {
    margin-top: 24px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 6px 26px 24px;
    box-shadow: var(--shadow-md);
}

.recent-orders-empty {
    color: var(--color-muted);
    font-size: 0.9rem;
    margin: 4px 0 8px;
}

.recent-orders-hint {
    color: var(--color-muted);
    font-size: 0.82rem;
    margin: 4px 0 10px;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    white-space: nowrap;
}

.data-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    background: var(--color-bg);
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
}

.data-table td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    white-space: normal;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table tbody tr:hover {
    background: var(--color-bg);
}

/* Denser variant for wide tables with many columns (e.g. Leads) */
.data-table-compact th,
.data-table-compact td {
    padding: 8px 11px;
    font-size: 0.82rem;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.data-table th.sortable:hover {
    color: var(--color-text);
}

.sort-indicator {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.35;
}

.data-table th.sortable.is-sorted .sort-indicator {
    opacity: 1;
    color: var(--color-primary);
}

.data-table .text-right {
    text-align: right;
}

/* Cap a handful of naturally long free-text columns (company name, email,
   inquiry text) so one outlier value can't blow out the whole table's
   width — the text wraps onto a second line instead of truncating or
   forcing every other column wider than it needs to be. Short columns
   (dates, qty, status) are left alone to size naturally. */
#LeadsTable td:nth-child(2),
#LeadsTable td:nth-child(5),
#LeadsTable td:nth-child(6) {
    max-width: 260px;
    word-break: break-word;
}

/* ---- Table toolbar (search box above a data table) --------------------- */

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.table-search {
    max-width: 340px;
    flex: 1;
}

.table-toolbar-count {
    font-size: 0.8rem;
    color: var(--color-muted);
    white-space: nowrap;
}

.data-table .muted {
    color: var(--color-muted-2);
}

/* ---- Status/priority badges -------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-error   { background: var(--color-error-bg);   color: var(--color-error); }
.badge-warning { background: var(--icon-amber-bg);    color: var(--icon-amber-fg); }
.badge-info    { background: var(--icon-sky-bg);      color: var(--icon-sky-fg); }
.badge-neutral { background: var(--color-bg);         color: var(--color-muted); }

.data-table-clickable tbody tr {
    cursor: pointer;
    transition: background 0.12s ease;
}

.data-table-clickable tbody tr:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    background: var(--color-primary-light);
}

.data-table-clickable tbody tr.is-editing {
    background: var(--color-primary-light);
}

.data-table-clickable tbody tr.is-editing td:first-child {
    box-shadow: inset 3px 0 0 var(--color-primary);
}

/* ---- Lead detail page --------------------------------------------------- */

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--color-muted);
    text-decoration: none;
    margin-bottom: 16px;
}

.back-link:hover {
    color: var(--color-text);
}

.back-link .icon {
    width: 15px;
    height: 15px;
}

.lead-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    align-items: start;
}

.lead-main,
.lead-side {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.lead-card {
    padding: 22px 26px 26px;
}

@media (max-width: 900px) {
    .lead-layout {
        grid-template-columns: 1fr;
    }
}

/* Read-only key/value grid (Lead Details section) */
.info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.info-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
}

.info-value {
    font-size: 0.92rem;
    color: var(--color-text);
    word-break: break-word;
}

@media (max-width: 700px) {
    .info-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 460px) {
    .info-grid { grid-template-columns: 1fr; }
}

/* Comment timeline (latest first) */
.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline-item {
    display: flex;
    gap: 12px;
    padding-bottom: 18px;
    position: relative;
}

.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 14px;
    bottom: 0;
    width: 1.5px;
    background: var(--color-border);
}

.timeline-dot {
    flex-shrink: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--color-primary);
    margin-top: 4px;
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.timeline-content {
    flex: 1;
    min-width: 0;
}

.timeline-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.timeline-author {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--color-text);
}

.timeline-author .icon {
    width: 13px;
    height: 13px;
    color: var(--color-muted-2);
}

.timeline-time {
    font-size: 0.74rem;
    color: var(--color-muted-2);
    white-space: nowrap;
}

.timeline-text {
    margin: 0;
    font-size: 0.88rem;
    color: var(--color-text);
    line-height: 1.5;
    word-break: break-word;
}

/* ---- Shared small pieces: amounts, tabs, monospace numbers ------------- */

.amount-display {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--icon-indigo-bg);
    color: var(--color-primary-dark);
    font-weight: 700;
    font-size: 0.9rem;
    text-align: right;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
    letter-spacing: 0.02em;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.filter-tab {
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--color-muted);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
}

.filter-tab:hover { color: var(--color-text); }

.filter-tab.is-active {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    border-color: var(--icon-indigo-bg);
}

/* ---- Transaction (PO) item grid & review box ---------------------------- */

.tx-item-grid {
    grid-template-columns: 1fr 1.4fr 1.3fr 0.7fr 0.9fr 0.9fr;
}

.doc-review {
    margin-top: 18px;
    padding: 14px 18px;
    border-radius: var(--radius);
    background: linear-gradient(180deg, #fafaff, #f6f7fb);
    border: 1px solid var(--color-border);
}

.doc-review-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.9rem;
}

.doc-review-total {
    border-top: 1px dashed var(--color-border-strong);
    margin-top: 6px;
    padding-top: 10px;
    font-size: 1rem;
}

.doc-review-total strong { color: var(--color-primary-dark); }

@media (max-width: 760px) {
    .tx-item-grid { grid-template-columns: 1fr 1fr; }
}

/* ---- Printable document sheet (view_transaction.php) -------------------- */

.doc-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.doc-sheet {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 36px 40px;
    color: #111;
}

.doc-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 26px;
}

.doc-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #4a5fa8;
    letter-spacing: 0.01em;
}

.doc-own {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 4px;
}

.doc-meta {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px 14px;
    margin: 0;
    font-size: 0.9rem;
}

.doc-meta dt { color: #666; }
.doc-meta dd { margin: 0; font-weight: 600; }

.doc-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    margin-bottom: 22px;
}

.doc-party-label {
    background: #3d4f86;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 5px 10px;
    margin-bottom: 8px;
}

.doc-party-name { font-weight: 700; font-size: 0.92rem; }
.doc-party-line { font-size: 0.86rem; color: #333; line-height: 1.45; }

.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.doc-table th {
    background: #3d4f86;
    color: #fff;
    padding: 7px 8px;
    text-align: left;
    font-size: 0.74rem;
    letter-spacing: 0.04em;
}

.doc-table td {
    border-bottom: 1px solid #d9d9d9;
    padding: 8px;
    vertical-align: top;
}

.doc-table .text-right { text-align: right; }

.doc-bottom {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    margin-top: 18px;
    flex-wrap: wrap;
}

.doc-comments {
    flex: 1;
    min-width: 220px;
    border: 1px solid #bbb;
}

.doc-comments-label {
    background: #d6d6d6;
    font-weight: 700;
    font-size: 0.82rem;
    padding: 5px 8px;
}

.doc-comments-body {
    padding: 8px;
    min-height: 70px;
    font-size: 0.86rem;
}

.doc-totals {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px 16px;
    margin: 0;
    min-width: 240px;
    font-size: 0.88rem;
}

.doc-totals dt { text-align: right; color: #333; }
.doc-totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.doc-totals .doc-grand {
    font-weight: 700;
    border-top: 2px solid #333;
    padding-top: 4px;
}

@media print {
    .no-print, .topbar { display: none !important; }
    body { background: #fff; }
    .page { padding: 0; max-width: none; }
    .doc-sheet { box-shadow: none; border: none; padding: 0; border-radius: 0; }
}

/* ---- Purchase order form: items on one line (stacked cards on phones) ---- */

.tx-form {
    padding: 22px 26px 24px;
}

.tx-section {
    padding: 18px 0;
    border-bottom: 1px solid var(--color-border);
}

.tx-section:last-of-type {
    border-bottom: 0;
}

.tx-header-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px 20px;
}

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

.tx-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.tx-section-head h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-heading);
}

.logo-upload {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.logo-preview {
    max-height: 64px;
    max-width: 200px;
    object-fit: contain;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    background: #fff;
}

.tx-table {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* A row is one line item. Desktop: all cells side by side. */
.tx-row {
    display: grid;
    grid-template-columns: 36px minmax(120px, 1.1fr) minmax(160px, 1.6fr) minmax(150px, 1.5fr) 80px 110px 90px 110px 110px 40px;
    gap: 8px;
    align-items: start;
    padding: 10px 12px;
    background: var(--color-surface);
    border: 0;
    border-bottom: 1px solid var(--color-border);
    border-radius: 0;
}

.tx-row:last-child {
    border-bottom: 0;
}

.tx-head {
    background: var(--color-bg);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    padding: 9px 12px;
    align-items: center;
}

.tx-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.tx-cell input,
.tx-cell select {
    padding: 8px 9px;
    font-size: 0.88rem;
    width: 100%;
    min-width: 0;
}

.tx-cell .error {
    margin-top: 0;
}

.tx-cell-label {
    display: none; /* shown on phones only; desktop uses the header row */
}

.tx-num {
    text-align: right;
    justify-content: center;
}

.tx-num .tx-value {
    font-weight: 600;
    font-size: 0.88rem;
    padding-top: 8px;
    font-variant-numeric: tabular-nums;
}

.tx-idx {
    align-items: center;
    padding-top: 6px;
}

.tx-actions {
    align-items: center;
    padding-top: 2px;
}

/* Footer: comments on the left, totals table on the right */
.tx-footer {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    align-items: start;
}

.tx-comments label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.tx-comments textarea {
    width: 100%;
}

.tx-right {
    display: block;
    text-align: right;
}

.totals-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.totals-table th,
.totals-table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--color-border);
}

.totals-table th {
    text-align: right;
    font-weight: 600;
    color: var(--color-muted);
    width: 40%;
}

.totals-table td {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.totals-table th label {
    margin: 0;
    font-weight: 600;
    color: var(--color-muted);
}

.totals-input {
    width: 130px;
    text-align: right;
    padding: 6px 8px;
    font-size: 0.9rem;
    display: inline-block;
}

.totals-table .totals-grand th,
.totals-table .totals-grand td {
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-heading);
    background: var(--icon-indigo-bg);
    border-bottom: 0;
}

/* Phones & small tablets: each line becomes a stacked card with labels */
@media (max-width: 1100px) {
    .tx-row {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    .tx-head { display: none; }
    .tx-idx { grid-column: 1 / 2; }
    .tx-cell-label { display: block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }
    .tx-row .tx-cell:nth-child(3) { grid-column: 1 / -1; }
    .tx-row .tx-cell:nth-child(4) { grid-column: 1 / -1; }
    .tx-row .tx-actions { grid-column: 4; align-items: flex-end; }
    .tx-num { text-align: left; justify-content: flex-start; }
    .tx-num .tx-value { padding-top: 0; }
}

@media (max-width: 760px) {
    .tx-form { padding: 14px 14px 18px; }
    .tx-header-grid { grid-template-columns: 1fr; }
    .tx-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tx-row .tx-cell:nth-child(n) { grid-column: auto; }
    .tx-row .tx-cell:nth-child(3),
    .tx-row .tx-cell:nth-child(4) { grid-column: 1 / -1; }
    .tx-row .tx-actions { grid-column: 2; }
    .tx-footer { grid-template-columns: 1fr; }
    .totals-table { width: 100%; }
    .totals-input { width: 110px; }
}
