:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --bg-app: #f1f5f9;
    --bg-surface: #ffffff;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-surface);
    box-shadow: var(--shadow-md);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    z-index: 10;
}

.logo-area h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.highlight {
    color: var(--primary);
}

.env-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.env-badge.prod {
    background: #d1fae5;
    color: #065f46;
}

.env-badge.dev {
    background: #fee2e2;
    color: #991b1b;
}

.controls-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#currentPeriodLabel {
    font-size: 1.1rem;
    font-weight: 600;
    min-width: 120px;
    text-align: center;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-app);
    color: var(--primary);
}

/* Navigation */
.main-nav {
    display: flex;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.nav-tab {
    background: transparent;
    border: none;
    padding: 1rem 1.5rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-tab:hover {
    color: var(--primary);
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Main Content */
.content-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    padding: 1.5rem;
    background: var(--bg-app);
}

.tab-content {
    display: none;
    height: 100%;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.btn-primary {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: white;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background-color: var(--bg-app);
}

/* Inputs */
input[type="text"],
input[type="time"],
input[type="color"] {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
}

input[type="text"]:focus {
    border-color: var(--primary);
}

/* Grid System */
.schedule-grid-container {
    flex: 1;
    overflow: auto;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    user-select: none;
}

.schedule-table {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
}

.schedule-table th,
.schedule-table td {
    border: 1px solid var(--border);
    padding: 0;
    text-align: center;
    height: 40px;
    vertical-align: middle;
}

.schedule-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    z-index: 5;
}

.col-user {
    position: sticky;
    left: 0;
    background: #f8fafc;
    z-index: 6;
    width: 150px;
    font-weight: 500;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

.schedule-table th.col-user {
    z-index: 7;
    /* Intersection of top and left sticky */
}

.date-header {
    min-width: 40px;
}

.weekend {
    background-color: #f1f5f9;
    color: #ef4444;
}

.shift-cell {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.1s;
    user-select: none;
}

.shift-cell:hover {
    filter: brightness(0.95);
}

.shift-cell.selected {
    background-color: rgba(59, 130, 246, 0.2) !important;
    outline: 2px solid var(--primary);
    position: relative;
    z-index: 10;
}

/* Settings Layout */
.settings-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: 100%;
    overflow: auto;
}

.settings-column {
    display: flex;
    flex-direction: column;
}

.settings-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.settings-card h3 {
    margin-bottom: 0;
    font-size: 1.1rem;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.list-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.time-inputs {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.item-list,
.item-list-small {
    list-style: none;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.item-list {
    max-height: none;
}

.item-list-small {
    max-height: 150px;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child {
    border-bottom: none;
}

.pattern-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: white;
    font-size: 0.8rem;
    min-width: 30px;
    text-align: center;
}

/* Rules Styles */
.rule-box {
    margin-bottom: 1rem;
}

.count-setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.count-setting-row:last-child {
    border-bottom: none;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-app);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.login-overlay.hidden {
    display: none;
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 400px;
    max-width: 90%;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.hidden {
    display: none !important;
}

/* Auth Mode Switcher */
.mode-switch {
    display: flex;
    background: #f1f5f9;
    border-radius: var(--radius);
    padding: 0.25rem;
    margin-bottom: 1.5rem;
}

.mode-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-radius: 6px;
    font-weight: 500;
}

.mode-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}


/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: var(--radius);
    width: 300px;
    box-shadow: var(--shadow-md);
}

.modal-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin: 1rem 0;
}

.modal-option-btn {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    cursor: pointer;
}

.modal-option-btn:hover {
    background: var(--bg-app);
}

/* Settings Table */
.settings-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.settings-table th,
.settings-table td {
    border: 1px solid var(--border);
    padding: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
}

.settings-table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
}

/* --- Data Input Styles --- */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    /* Firefox */
    appearance: none;
    text-align: center;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    /* Center the input boxes horizontally */
}

.settings-table input[type="number"] {
    width: 50px;
    text-align: center;
    padding: 0.25rem;
}

/* Drag and Drop Styles */
.list-item {
    transition: background-color 0.2s;
}

tr.list-item {
    display: table-row;
    /* Ensure table rows don't break with flex */
}

.list-item.dragging {
    opacity: 0.5;
    background-color: var(--bg-app);
}

.list-item.drag-over {
    border-top: 2px solid var(--primary);
}

/* For table rows, border-top might not work well on tr, use outline or highlight cells */
tr.list-item.drag-over td {
    border-top: 2px solid var(--primary);
}

.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drag-handle:active {
    cursor: grabbing;
}

.drag-handle svg {
    width: 16px;
    height: 16px;
}