/* ===== CUSTOM PROPERTIES ===== */
:root {
    --primary:      #2563eb;
    --primary-lt:   #eff6ff;
    --text:         #1e293b;
    --muted:        #64748b;
    --border:       #e2e8f0;
    --bg-subtle:    #f8fafc;
    --danger:       #ef4444;
    --success:      #1d4ed8;
    --shadow:       0 4px 24px rgba(0,0,0,.10), 0 1px 4px rgba(0,0,0,.06);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: #dde1e7;
}

/* ===== TOOLBAR ===== */
.toolbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--text);
    color: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
}

.toolbar-brand {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .3px;
    opacity: .9;
}

.toolbar-actions { display: flex; gap: 10px; }

.btn-toolbar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 6px;
    background: rgba(255,255,255,.1);
    color: white;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s;
}
.btn-toolbar:hover { background: rgba(255,255,255,.2); }

/* ===== PAGE BACKGROUND ===== */
.page-bg {
    min-height: 100vh;
    padding: 72px 20px 48px;
    display: flex;
    justify-content: center;
}

/* ===== DOCUMENT (paper) ===== */
.document {
    background: #fff;
    width: 100%;
    max-width: 880px;
    min-height: 297mm;
    padding: 52px 68px;
    box-shadow: var(--shadow);
    border-radius: 3px;
}

/* ===== DOCUMENT HEADER ===== */
.doc-header {
    text-align: center;
    padding-bottom: 26px;
    margin-bottom: 32px;
    border-bottom: 2.5px solid var(--text);
}

.doc-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: 7px;
    color: var(--text);
    text-transform: uppercase;
}

/* ===== PATIENT INFO ===== */
.patient-info {
    margin-bottom: 36px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.info-group {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
}

.info-group .info-field { flex: 1; min-width: 180px; }

.info-field--full { width: 100%; }

.info-field {
    display: flex;
    align-items: baseline;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 5px;
}

.info-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: #94a3b8;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 54px;
}

.info-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    padding: 2px 0;
}

.info-input--lg { font-size: 18px; font-weight: 500; }

.info-input::placeholder { color: #c8d2dc; font-style: italic; }

/* Date input fix */
input[type="date"].info-input { color: var(--text); }

/* ===== SECTION TITLE ===== */
.section-title {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.6px;
    color: #94a3b8;
    margin-bottom: 14px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--border);
}

/* ===== CHART SECTION ===== */
.chart-section { margin-bottom: 36px; }

.chart-tip {
    font-size: 12px;
    color: #94a3b8;
    font-style: italic;
    margin-bottom: 12px;
}

.dental-chart {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 22px 20px 16px;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    gap: 0;
    transition: border-color .2s, background .2s;
}

.dental-chart.active-input {
    border-color: var(--primary);
    background: var(--primary-lt);
}

.jaw-labels {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 6px;
    margin-bottom: 6px;
}

.jaw-label {
    font-size: 9.5px;
    color: #b0bec5;
    font-style: italic;
    letter-spacing: .3px;
}

/* ===== TEETH ROWS ===== */
.teeth-row {
    display: flex;
    align-items: flex-end;  /* upper: bodies touch midline at bottom */
    gap: 0;
}

.teeth-row.lower {
    align-items: flex-start; /* lower: bodies touch midline at top */
    margin-top: 4px;
}

.quadrant-gap {
    width: 1.5px;
    background: #cbd5e1;
    align-self: stretch;
    margin: 0 4px;
    border-radius: 1px;
}

.jaw-midline {
    width: 90%;
    height: 1.5px;
    background: linear-gradient(to right, transparent, #c4cfd8 15%, #c4cfd8 85%, transparent);
    margin: 6px 0;
}

/* ---- Inner scrollable container for teeth rows ---- */
.teeth-canvas {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
}
.teeth-canvas::-webkit-scrollbar { height: 4px; }
.teeth-canvas::-webkit-scrollbar-track { background: transparent; }
.teeth-canvas::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ===== SINGLE TOOTH ===== */
.tooth {
    --tooth-fill:   #ffffff;
    --tooth-stroke: #D0D0D0;
    --tooth-sw:     1.5;

    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    user-select: none;
    margin: 0;
    gap: 1px;
}

/* ---- SVG shape ---- */
.tooth-svg {
    display: block;
    transition: transform 150ms ease, filter 150ms ease;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.07));
}

/* Upper teeth: flip vertically so crown faces midline */
.tooth-svg--upper { transform: scaleY(-1); }

/* ---- Sizes by type (width drives proportional height via SVG viewBox) ---- */
/* Sizes derived from anatomical ratios (technical4.txt). Central incisor = 100%.
   Width drives proportional height via SVG viewBox aspect ratio. */
.t-central    .tooth-svg { width: 44px; } /* 100%  */
.t-lateral    .tooth-svg { width: 41px; } /*  91%  */
.t-canine     .tooth-svg { width: 49px; } /* 110%  */
.t-premolar-1 .tooth-svg { width: 38px; } /*  87%  */
.t-premolar-2 .tooth-svg { width: 37px; } /*  83%  */
.t-molar-1    .tooth-svg { width: 46px; } /*  87%  (square vb) */
.t-molar-2    .tooth-svg { width: 43px; } /*  83%  (square vb) */
.t-wisdom     .tooth-svg { width: 40px; } /*  77%  (square vb) */

/* ---- Tooth number ---- */
.tooth-num {
    font-size: 9px;
    line-height: 14px;
    color: #90a4ae;
    font-weight: 500;
    padding: 0 1px;
}

/* ---- Hover ---- */
.tooth:not(.selected):hover {
    --tooth-stroke: var(--primary);
}

.tooth:not(.selected):hover .tooth-svg {
    transform: scale(1.05);
    filter: drop-shadow(0 2px 5px rgba(37,99,235,.18));
}

/* Maintain flip + add scale for upper teeth on hover */
.tooth.upper:not(.selected):hover .tooth-svg {
    transform: scaleY(-1) scale(1.05);
}

/* ---- Selected ---- */
.tooth.selected {
    --tooth-fill:   #DCEEFF;
    --tooth-stroke: #3B82F6;
    --tooth-sw:     2;
}

.tooth.selected .tooth-num {
    color: var(--primary);
    font-weight: 700;
}

/* ===== TEETH SUMMARY ===== */
.teeth-summary {
    margin-top: 11px;
    font-size: 13px;
    color: var(--muted);
}

.teeth-summary-label {
    font-weight: 600;
    margin-right: 5px;
}

/* ===== PLAN SECTION ===== */
.plan-section { margin-bottom: 32px; }

/* ===== STAGE ===== */
.stage {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 18px;
    overflow: hidden;
}

.stage-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 15px;
    background: #f1f5f9;
    border-bottom: 1px solid var(--border);
}

.stage-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}

.stage-name-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    font-family: inherit;
}

.stage-name-input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 3px 7px;
    border-radius: 4px;
    color: #94a3b8;
    font-size: 20px;
    line-height: 1;
    transition: color .12s, background .12s;
}

.btn-icon:hover {
    color: var(--danger);
    background: #fef2f2;
}

/* ===== PROCEDURES TABLE ===== */
.proc-table {
    width: 100%;
    border-collapse: collapse;
}

.proc-table th {
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #94a3b8;
    padding: 8px 10px;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.proc-table td {
    padding: 4px 7px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.proc-table tbody tr:last-child td { border-bottom: none; }

.proc-table tbody tr:hover td { background: #fdfdfe; }

.p-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    padding: 4px 5px;
    border-radius: 3px;
    transition: background .1s;
}

.p-input:focus { background: var(--primary-lt); }
.p-input::placeholder { color: #d1d5db; }
.p-input[type="number"] { text-align: right; -moz-appearance: textfield; }
.p-input[type="number"]::-webkit-inner-spin-button,
.p-input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

.teeth-input { cursor: text; }

.proc-total-cell {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    padding: 4px 8px;
}

.btn-remove-proc {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--danger);
    font-size: 19px;
    line-height: 1;
    opacity: .3;
    padding: 2px 7px;
    border-radius: 3px;
    transition: opacity .12s;
}
.btn-remove-proc:hover { opacity: 1; }

/* ===== STAGE FOOTER ===== */
.stage-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 15px;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border);
}

.btn-add-proc {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background .12s;
}
.btn-add-proc:hover { background: var(--primary-lt); }

.stage-total {
    font-size: 13px;
    color: var(--muted);
}

.stage-total-val {
    font-weight: 700;
    color: var(--text);
    margin-left: 5px;
}

/* ===== ADD STAGE BUTTON ===== */
.btn-add-stage {
    width: 100%;
    padding: 13px;
    border: 2px dashed #c9d4df;
    border-radius: 8px;
    background: none;
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    letter-spacing: .3px;
}
.btn-add-stage:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-lt);
}

/* ===== GRAND TOTAL ===== */
.grand-total-area {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 36px;
    padding-top: 22px;
    margin-top: 6px;
    border-top: 2.5px solid var(--text);
}

.grand-label {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 2.5px;
    color: var(--muted);
}

.grand-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    min-width: 220px;
    text-align: right;
}

/* ===== PRINT ===== */
@media print {
    body { background: #fff; }

    .no-print { display: none !important; }

    .page-bg {
        padding: 0;
        display: block;
        min-height: unset;
    }

    .document {
        max-width: none;
        width: 100%;
        padding: 18mm 16mm;
        box-shadow: none;
        min-height: unset;
        border-radius: 0;
    }

    .dental-chart {
        background: #fff;
        border-color: #ccc;
        max-width: none;
        zoom: 0.88;
    }

    .teeth-canvas {
        overflow-x: visible;
    }

    .stage { break-inside: avoid; }

    .stage-header { background: #f5f5f5; }

    .stage-footer { background: #fafafa; }

    .proc-table th { background: #f5f5f5; }
}
