:root {
    --primary: #1565C0;
    --primary-dark: #0D47A1;
    --primary-light: #42A5F5;
    --bg: #F0F4F8;
    --card: #FFFFFF;
    --text: #263238;
    --text-sec: #607D8B;
    --border: #DEE5ED;
    --sidebar-w: 310px;
    --header-h: 50px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ── Header ── */
#header {
    height: var(--header-h);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(13, 71, 161, 0.25);
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.logo small {
    font-weight: 400;
    opacity: 0.65;
    font-size: 13px;
}

#menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.15s;
}
#menu-toggle:hover { background: rgba(255,255,255,0.15); }

/* ── Content ── */
#content {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ── Viewport ── */
#viewport {
    flex: 1;
    position: relative;
    background: linear-gradient(160deg, #e6ecf4 0%, #f0f4f8 40%, #e9eff7 100%);
    min-width: 0;
}

#dental-canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    outline: none;
}

#hint, #hint-touch {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--text-sec);
    background: rgba(255,255,255,0.82);
    padding: 5px 14px;
    border-radius: 20px;
    backdrop-filter: blur(6px);
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.01em;
}
#hint-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
    #hint { display: none; }
    #hint-touch { display: block; }
}

/* ── Sidebar ── */
#sidebar {
    width: var(--sidebar-w);
    background: var(--card);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: #c5cdd6 transparent;
}
#sidebar::-webkit-scrollbar { width: 5px; }
#sidebar::-webkit-scrollbar-thumb { background: #c5cdd6; border-radius: 3px; }

.panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: var(--card);
}

.panel h3 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 8px;
}

.panel input[type="text"],
.panel input[type="date"] {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-bottom: 5px;
}
.panel input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.12);
}

.muted {
    color: var(--text-sec);
    font-size: 12px;
    font-style: italic;
}

/* ── Condition Buttons ── */
#condition-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.cond-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-family: var(--font);
    font-size: 11px;
    color: var(--text);
    transition: all 0.12s;
    line-height: 1.3;
}
.cond-btn:hover {
    border-color: var(--primary-light);
    background: #e3f2fd;
}
.cond-btn:active {
    transform: scale(0.97);
}

.cond-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: inset 0 -1px 2px rgba(0,0,0,0.15);
}

/* ── Preset Buttons ── */
#preset-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.preset-btn {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: white;
    cursor: pointer;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text);
    text-align: left;
    transition: all 0.12s;
}
.preset-btn:hover {
    border-color: var(--primary-light);
    background: #e3f2fd;
    color: var(--primary-dark);
}
.preset-btn:active { transform: scale(0.98); }

/* ── Tooth Info ── */
.tooth-info-fdi {
    font-size: 30px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 4px;
}
.tooth-info-name {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.tooth-info-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 12px;
    color: var(--text-sec);
}
.tooth-info-row span:last-child {
    font-weight: 500;
    color: var(--text);
}

/* ── Summary ── */
#summary-content {
    max-height: 180px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid #f0f2f5;
}
.summary-row:last-child { border-bottom: none; }

.summary-tooth {
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    min-width: 28px;
}

.summary-cond {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    color: white;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* ── 3D Labels ── */
.tooth-label {
    color: #546e7a;
    font-size: 10px;
    font-weight: 600;
    font-family: var(--font);
    background: rgba(255,255,255,0.78);
    padding: 1px 4px;
    border-radius: 3px;
    pointer-events: none;
    user-select: none;
    line-height: 1.2;
    backdrop-filter: blur(2px);
    transition: background 0.15s, color 0.15s;
}
.tooth-label.selected {
    background: var(--primary);
    color: white;
}

/* ── Mobile ── */
@media (max-width: 840px) {
    #content {
        flex-direction: column;
    }
    #viewport {
        flex: 1 1 55%;
        min-height: 45vh;
    }
    #sidebar {
        width: 100%;
        max-height: 45vh;
        border-left: none;
        border-top: 1px solid var(--border);
        flex-direction: row;
        flex-wrap: wrap;
        align-content: flex-start;
        --sidebar-w: 100%;
    }
    #sidebar .panel {
        flex: 1 1 calc(50% - 5px);
        min-width: 180px;
    }
    #menu-toggle { display: block; }
    #sidebar.collapsed { display: none; }

    .tooth-label { font-size: 8px; padding: 0 3px; }
}

@media (max-width: 500px) {
    #sidebar .panel { flex: 1 1 100%; }
    .logo span { font-size: 14px; }
    #header { padding: 0 10px; }
    .cond-btn { font-size: 10px; padding: 4px 7px; }
}
