/* --- VARIABLES & THEME --- */
:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --bg-body: #F3F4F6;
    --bg-card: #FFFFFF;
    --text-main: #1F2937;
    --text-light: #6B7280;
    --border: #E5E7EB;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-body: #111827;
    --bg-card: #1F2937;
    --text-main: #F9FAFB;
    --text-light: #9CA3AF;
    --border: #374151;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-top: env(safe-area-inset-top);
    transition: background-color 0.3s, color 0.3s;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Authentication Views */
#auth-view,
#admin-detected-view,
#access-denied-view {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    display: block;
    margin: auto;
}

.auth-logo {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

.auth-title {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.auth-subtitle {
    color: var(--text-light);
    margin-bottom: 2rem;
    font-size: 0.9rem;
    line-height: 1.4;
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 1rem 0.5rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-light);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.auth-tab:hover {
    color: var(--primary);
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
    text-align: left;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 16px;
    height: 50px;
    background-color: var(--bg-card);
    color: var(--text-main);
    transition: border-color 0.2s, background-color 0.3s, color 0.3s;
    appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.9rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.1s, background-color 0.2s;
    font-size: 1rem;
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.98);
}

.btn-full {
    width: 100%;
    margin-top: 0.5rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-back {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 100%;
    justify-content: center;
}

.btn-back:hover {
    background: var(--bg-body);
}

/* App View Base */
#app-view,
#admin-view {
    width: 100%;
    max-width: 1000px;
    align-self: flex-start;
    margin-top: 0;
}

body.logged-in {
    justify-content: flex-start;
    padding-top: 0;
}

.container,
.card {
    background: var(--bg-card);
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    /* Auto wrap on mobile */
    gap: 1rem;
}

.header-left {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.header-left h1 {
    font-size: 1.2rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.week-label {
    font-size: 0.8rem;
    color: var(--text-light);
    font-weight: 500;
    display: block;
    margin-top: 4px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-icon {
    background: var(--bg-body);
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--border);
}

.btn-logout {
    background: var(--bg-body);
    border: none;
    padding: 0.5rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}

.btn-logout:hover {
    background: var(--border);
}

/* Tables */
.table-wrapper {
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background-color: var(--bg-body);
    text-align: left;
    padding: 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 0.8rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text-main);
}

.input-cell {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    height: 45px;
    background: var(--bg-card);
    color: var(--text-main);
}

.input-cell:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Multi-entry rows */
.day-header-row td {
    background-color: var(--bg-body);
    border-bottom: 2px solid var(--border);
    padding: 0.8rem 1rem !important;
}

.sub-entry-row td {
    border-bottom: 1px solid var(--border);
}

.add-entry-row td {
    border-bottom: 2px solid var(--border);
}

.day-total {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--success);
}

.add-entry-btn {
    background: transparent;
    border: 1px dashed var(--primary);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.add-entry-btn:hover {
    background: var(--primary);
    color: white;
    border-style: solid;
}

.add-entry-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.remove-entry-btn {
    background: var(--danger);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    min-width: 36px;
    height: 36px;
}

.remove-entry-btn:hover {
    background: #DC2626;
    transform: scale(1.05);
}

.remove-entry-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Footer */
.table-footer {
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05);
}

.summary-text {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-check {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.7rem 1rem;
}

.btn-check:hover {
    background: var(--border);
}

.btn-submit {
    background-color: var(--primary);
    color: white;
    padding: 0.7rem 1rem;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn-submit:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-submit:disabled {
    background-color: #CBD5E1;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Validation */
tr.validated td {
    background-color: rgba(16, 185, 129, 0.1);
}

tr.validated .input-cell {
    border-color: var(--success);
    font-weight: 600;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    left: 20px;
    right: 20px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-left: 4px solid var(--primary);
    animation: slideIn 0.3s ease-out;
    width: 100%;
    box-sizing: border-box;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

.toast.warning {
    border-color: var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Credits */
.dev-credits {
    width: 100%;
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-bottom: 6rem;
    /* Space for footer on mobile */
}

.dev-credits .version {
    display: block;
    font-size: 0.7rem;
    color: var(--text-light);
    margin-bottom: 0.3rem;
    font-weight: 600;
    letter-spacing: 1px;
}

.dev-credits .company {
    display: block;
    font-size: 0.85rem;
    color: var(--text-main);
}

.dev-credits a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.dev-credits a:hover {
    text-decoration: underline;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    width: 90%;
    max-width: 400px;
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.modal-footer {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Desktop */
@media (min-width: 769px) {
    body {
        padding-top: 2rem;
    }

    #app-view,
    #admin-view {
        margin-top: 2rem;
        padding-bottom: 0;
    }

    .container,
    .card {
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        min-height: auto;
    }

    .table-footer {
        position: static;
        background: var(--bg-body);
        padding: 1.5rem 2rem;
        box-shadow: none;
        border-radius: 0 0 var(--radius) var(--radius);
    }

    .toast-container {
        left: auto;
        width: auto;
        max-width: 350px;
        bottom: 20px;
    }

    header {
        border-radius: var(--radius) var(--radius) 0 0;
    }

    .dev-credits {
        margin-bottom: 2rem;
    }
}

/* MOBILE RESPONSIVE (Cards) */
@media (max-width: 768px) {

    /* Hide Table Header */
    thead {
        display: none;
    }

    table,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tr {
        background: var(--bg-card);
        margin-bottom: 1rem;
        border-radius: var(--radius);
        border: 1px solid var(--border);
        padding: 1rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    td {
        padding: 0.5rem 0;
        border: none;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    /* First cell (Date) needs to be row-like and prominent */
    td:first-child {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border);
        padding-bottom: 0.8rem;
        margin-bottom: 0.5rem;
    }

    .date-display {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        font-weight: 700;
        font-size: 1rem;
    }

    .day-name {
        font-size: 1rem;
        color: var(--primary);
        text-transform: capitalize;
        margin-bottom: 0;
    }
}