:root {
    --bg-color: #f7f7f7;
    --text-color: #333;
    --panel-bg: #ffffff;
    --accent-color: #ff9800;
    /* Toaster Orange */
    --accent-hover: #e68900;
    --secondary-color: #aaa;
    --border-radius: 16px;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

    --success-color: #4CAF50;
    --error-color: #E53935;
    --warn-bg: #fff3cd;
    --warn-text: #856404;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --panel-bg: #1e1e1e;
    --secondary-color: #666;
}

/* Lock Screen */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.lock-content {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    text-align: center;
    width: 90%;
    max-width: 320px;
}

.dark-mode .lock-content {
    background: #2c2c2c;
    color: #fff;
}

.lock-content input {
    font-size: 1.5rem;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    margin: 15px 0;
    text-align: center;
    letter-spacing: 5px;
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 420px;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
.app-header {
    padding: 20px;
    text-align: center;
    flex-shrink: 0;
}

.app-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    letter-spacing: 2px;
}

/* Main Stage */
.main-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    width: 100%;
    /* padding default is 0 via reset, ensure full height usage */
}

/* Ideal Display */
#ideal-sleep-display {
    text-align: center;
    /* Removed margin-bottom to let flexbox handle spacing */
    width: 100%;
}

.ideal-label {
    font-size: 1.1rem;
    color: var(--secondary-color);
    margin-bottom: 5px;
}

.ideal-value {
    /* Match button text size (1.8rem) */
    font-size: 1.8rem;
    font-weight: bold;
}

.ideal-value-sub {
    font-size: 1.2rem;
    color: var(--accent-color);
}

/* Button Container */
.button-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    /* Reserve space for buttons */
}

/* Sleep Info Text */
#sleep-info {
    font-size: 2.5rem;
    font-weight: bold;
    color: #555;
    /* Margin handled by flexbox */
    animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

.invisible {
    visibility: hidden;
    opacity: 0;
}

.hidden {
    display: none !important;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: transform 0.1s;
}

button:active {
    transform: scale(0.95);
}

/* Big Circle Button Base */
.btn-circle-ui {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    font-size: 1.8rem;
    font-weight: bold;
    color: white;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Good Night - Midnight Blue */
#btn-good-night {
    background-color: #2C3E50;
}

/* Good Morning - Carrot (Matching Density) */
#btn-good-morning {
    background-color: #E67E22;
}

/* Standardized Buttons */
.btn-std {
    height: 44px;
    padding: 0 24px;
    border-radius: 22px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.2s, transform 0.1s;
}

.btn-std:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-std:active {
    transform: scale(0.96);
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-secondary {
    background-color: #e0e0e0;
    color: #333;
}

.dark-mode .btn-secondary {
    background-color: #444;
    color: #ddd;
}

.btn-danger {
    background-color: #ffebee;
    color: var(--error-color);
}

.dark-mode .btn-danger {
    background-color: #3e2e2e;
}

/* Settings Modal Buttons: Unified Width */
.settings-styles .btn-std {
    width: 100%;
    min-width: 0;
    padding: 0 10px;
    box-sizing: border-box;
    /* Critical for uniform width */
}

.settings-grid-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    /* Use consistent gap */
    width: 100%;
    margin-top: 10px;
}

/* Notion Test Button: Match "Good Night" Blue */
#btn-notion-test {
    background-color: #2C3E50 !important;
    color: white;
}

/* Accordion Styles */
details {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
}

.dark-mode details {
    background: rgba(255, 255, 255, 0.05);
}

summary {
    padding: 15px;
    font-weight: bold;
    cursor: pointer;
    list-style: none;
    /* Hide default triangle */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

summary::-webkit-details-marker {
    display: none;
}

summary::after {
    content: '▼';
    font-size: 1.0rem;
    color: var(--secondary-color);
    transition: transform 0.2s;
    transform: rotate(-90deg);
    /* Closed state: Points Right */
}

details[open] summary::after {
    transform: rotate(0deg);
    /* Open state: Points Down */
}

.details-content {
    padding: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.details-content>*:last-child {
    margin-bottom: 0;
}

/* Footer */
.footer-area {
    /* Position relative in flex flow */
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 40px;
    /* Space between History and Settings */
    padding: 0 20px;
    box-sizing: border-box;
}

.footer-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.footer-label {
    font-size: 0.8rem;
    color: var(--secondary-color);
}

.btn-icon-small {
    background: var(--panel-bg);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    color: var(--text-color);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center vertically */
    backdrop-filter: blur(5px);
}

/* Animation for modal pop in */
.modal-content {
    background: var(--panel-bg);
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    /* Uniform radius */
    padding: 25px;
    box-sizing: border-box;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy pop */
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.result-content {
    text-align: center;
    padding-bottom: 40px;
}

.result-content span {
    display: block;
    margin: 10px 0;
    font-size: 1.2rem;
}

#msg-icon {
    font-size: 3rem;
}

#msg-title {
    font-weight: bold;
}

#msg-duration {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-color);
}

/* History List */
.history-list {
    margin-top: 15px;
    max-height: 50vh;
    overflow-y: auto;
}

.history-item {
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    /* For overlay */
    transition: background-color 0.2s;
}

.history-item.selected {
    background-color: #ddd;
    /* Darker gray for selection */
}

.history-item.selected::after {
    content: '✔';
    position: absolute;
    left: 10px;
    /* Move to left */
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    color: white;
    background-color: #007bff;
    /* Blue background */
    width: 30px;
    height: 30px;
    border-radius: 50%;
    /* Circle */
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;

    /* Click pass-through */
}

.dark-mode .history-item {
    background-color: rgba(255, 255, 255, 0.05);
}

.dark-mode .history-item.selected {
    background-color: #444;
}

.h-icon {
    font-size: 1.0rem;
}

.h-info {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.h-date {
    font-size: 0.8rem;
    color: var(--secondary-color);
}

.h-range {
    font-size: 1rem;
}

.h-duration {
    font-size: 1.1rem;
    font-weight: bold;
    margin-top: 2px;
    white-space: nowrap;
    /* Prevent line break */
    display: inline-block;
    min-width: 90px;
    text-align: right;
}

.h-diff {
    font-size: 0.9rem;
    margin-left: 5px;
}

.diff-good {
    color: var(--success-color);
}

.diff-bad {
    color: var(--error-color);
}

.diff-warn {
    color: #2196F3;
    /* Blue for Excess */
}

.h-memo {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-top: 4px;
    /* Removed border and padding for alignment */
    /* border-left: 2px solid var(--accent-color); */
    /* padding-left: 5px; */
}

.h-sync-area {
    display: flex;
    align-items: center;
    gap: 5px;
}

.h-err {
    font-size: 0.75rem;
    color: var(--error-color);
    margin-top: 2px;
}

.h-checkbox {
    width: 20px;
    height: 20px;
    margin-right: 5px;
}

.empty-state {
    text-align: center;
    color: var(--secondary-color);
    margin-top: 20px;
}

/* Settings Styles */
.settings-section {
    margin-bottom: 25px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 15px;
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    color: var(--accent-color);
}

.form-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.form-group.row {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.form-group label {
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 0.95rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="time"] {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-color);
    color: var(--text-color);
}

.note-box {
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 15px;
    box-sizing: border-box;
}

.note-box p {
    margin: 0;
    line-height: 1.5;
}

.note-box.warn {
    background-color: var(--warn-bg);
    color: var(--warn-text);
}

.dark-mode .note-box.warn {
    background-color: #332b00;
    color: #ffda6a;
}

.action-row {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.btn-small {
    padding: 4px 8px;
    /* Reduced padding */
    font-size: 0.85rem;
    /* Slightly smaller text */
    border-radius: 8px;
    background: #e0e0e0;
    color: #333;
}

.btn-danger {
    background: var(--error-color);
    /* Use error color variable */
    color: white;
    /* White text for contrast */
}

.status-text {
    margin-top: 5px;
    font-size: 0.85rem;
    font-weight: bold;
}

.status-text.neutral {
    color: var(--secondary-color);
}

.status-text.success {
    color: var(--success-color);
}

.status-text.error {
    color: var(--error-color);
}

.btn-modal-action {
    background: transparent;
    border: 1px solid var(--secondary-color);
    padding: 5px 15px;
    border-radius: 15px;
    color: var(--text-color);
}

.text-danger {
    color: var(--error-color);
    border-color: var(--error-color);
}

.history-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

/* Mobile Scrollbar fix */
::-webkit-scrollbar {
    width: 6px;
}


/* Result Modal Icon Size */
/* Result Modal Header */
.result-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

/* Icon removed */

.result-content #msg-title {
    font-weight: bold;
    font-size: 1.5rem;
    /* Match icon size directly */
    line-height: 1;
    /* Match icon line-height */
    display: flex;
    /* Helps with vertical alignment in some browsers */
    align-items: center;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Custom Modal Overlay (High Z-index for Confirm/Alert) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    z-index: 2000;
    /* Override default */
}

/* Standard Button for Modals */
.btn-std {
    padding: 8px 15px;
    /* Reduced padding to fit */
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: bold;
    white-space: nowrap;
    /* Prevent wrapping */
    border: none;
    cursor: pointer;
    background-color: #e0e0e0;
    /* Default gray for secondary */
    color: #333;
}

/* Fixed width for top control buttons */
.btn-control-fixed {
    width: 120px;
    text-align: center;
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
    /* For flex buttons if any */
}

/* Specific Override for Danger Buttons using btn-std */
.btn-std.btn-danger {
    background-color: var(--error-color);
    color: white;
}

/* Confirm & Alert Modal Text */
#confirm-message {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-color);
    margin-bottom: 25px;
}


.sub-details {
    background: transparent !important;
    box-shadow: none !important;
    margin-left: 0 !important;
    margin-top: 0 !important;
    border: none;
    border-top: none !important;
    padding: 0 !important;
}

.sub-details summary {
    justify-content: space-between !important;
    gap: 10px;
    padding: 5px 0 !important;
    font-size: 0.9rem;
    font-weight: normal;
    color: var(--text-color);
}

.sub-details summary::-webkit-details-marker {
    display: none;
}

/* Overwrite the arrow icon logic for this specific class */
.sub-details summary::after {
    content: '+' !important;
    transform: none !important;
    font-size: 1.5rem;
    font-weight: normal;
    color: var(--secondary-color);
    margin-left: 0;
}

.sub-details[open] summary::after {
    content: '-' !important;
    transform: none !important;
}


.notion-warn-top {
    font-size: 0.75rem;
    color: var(--secondary-color);
    margin-bottom: 4px;
    white-space: nowrap;
}

.notion-warn-bottom {
    font-size: 0.75rem;
    color: var(--error-color);
    margin-top: 4px;
    white-space: nowrap;
}