:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --background-dark: #0f172a;
    --background-light: #f8fafc;
    --card-bg-light: #ffffff;
    --card-bg-dark: #1e293b;
    --text-light: #1f2937;
    --text-dark: #f9fafb;
    --working-green: #10b981; /* 9 AM - 5 PM */
    --neutral-yellow: #f59e0b; /* 7 AM - 9 AM & 5 PM - 9 PM */
    --sleeping-red: #ef4444; /* 9 PM to 6:59 AM */
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-light);
    color: var(--text-light);
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    /* Subtle World Map/Timezone Background using radial gradients */
    background-image: radial-gradient(circle at 10% 50%, rgba(79, 70, 229, 0.05), transparent),
                        radial-gradient(circle at 90% 80%, rgba(20, 184, 166, 0.05), transparent);
    background-size: 100% 100%;
}

/* --- Dark Mode Toggle and Text Color Fixes --- */
body.dark-mode {
    background-color: var(--background-dark);
    color: var(--text-dark); /* Ensure default text is light */
}

body.dark-mode .controls-section h2, 
body.dark-mode label {
    color: var(--text-dark); /* Ensure section titles and labels are light */
}

body.dark-mode .card {
    background-color: var(--card-bg-dark);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

body.dark-mode input, body.dark-mode select, body.dark-mode button:not(.time-control-btn) {
    background-color: #334155;
    color: var(--text-dark);
    border-color: #475569;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 20px 0;
}

h1 {
    font-weight: 700;
    margin-bottom: 5px;
    color: var(--primary-color);
}

/* --- Form and Controls --- */
.controls-section {
    background-color: var(--card-bg-light);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
    border: 1px solid #e2e8f0;
}
body.dark-mode .controls-section {
    background-color: var(--card-bg-dark);
    border-color: #475569;
}


.input-group, .time-controls {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    margin-bottom: 15px;
}

.input-item {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

label {
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

select, input[type="datetime-local"], button, input[type="range"] {
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
    transition: all 0.2s;
}

select:focus, input:focus, button:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.3);
}

.action-button {
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}

.action-button:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
}

.time-controls button {
    flex-grow: 1;
}

/* Range Slider Styling */
input[type="range"] {
    -webkit-appearance: none;
    height: 8px;
    background: #e2e8f0;
    cursor: pointer;
    flex-grow: 1;
    padding: 0;
}
body.dark-mode input[type="range"] {
    background: #475569;
}


input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: grab;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    margin-top: -5px; /* Adjust based on track height */
}

.time-controls {
    align-items: center;
}

.time-controls .input-item {
    flex-grow: 3;
}

/* Time Control Buttons */
.time-control-btn {
    background-color: #f1f5f9;
    color: var(--text-light);
    border: 1px solid #e2e8f0;
    font-size: 0.9rem;
    padding: 8px 12px;
    flex-grow: 1;
}
body.dark-mode .time-control-btn {
    background-color: #334155;
    color: var(--text-dark);
    border-color: #475569;
}
.time-control-btn:hover {
    background-color: #e2e8f0;
}
body.dark-mode .time-control-btn:hover {
    background-color: #475569;
}

/* --- City Cards Container --- */
#city-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    background-color: var(--card-bg-light);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    position: relative;
    cursor: grab;
    transition: all 0.2s;
    border: 1px solid #e2e8f0;
}
body.dark-mode .card {
    border-color: #334155;
}


.card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.card.highlight {
    border: 3px solid var(--primary-color);
    box-shadow: 0 0 20px rgba(79, 70, 229, 0.5);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.flag-country {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* New: Flag Emoji Styling */
.flag-emoji {
    font-size: 2.5rem; 
    line-height: 1;
    margin-right: 5px;
}

.city-name {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    color: var(--primary-color);
}

.country-name {
    font-size: 0.9rem;
    font-weight: 400;
    color: #64748b;
}
body.dark-mode .country-name {
    color: #94a3b8;
}

.time-display {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 10px 0 5px;
    letter-spacing: -1px;
}

.date-display {
    font-size: 1rem;
    color: #475569;
    margin-bottom: 10px;
}
body.dark-mode .date-display {
    color: #a1a1aa;
}

.timezone-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 15px;
    border-top: 1px dashed #e5e7eb;
}
body.dark-mode .timezone-details {
    border-top-color: #374151;
}

.tz-info span {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 2px 0;
    /* Ensure TZ info text is visible in dark mode by default,
        but overridden in night time (is-night) */
    color: var(--text-light); 
}
body.dark-mode .tz-info span {
        color: var(--text-dark);
}

.tz-info small {
    font-weight: 400;
    color: #64748b;
}
body.dark-mode .tz-info small {
    color: #94a3b8;
}

.dst-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 9999px;
    background-color: #facc15;
    color: #713f12;
    opacity: 0.8;
}

.holiday-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 9999px;
    background-color: #f97316;
    color: white;
    margin-top: 5px;
    text-align: center;
}

.remove-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.remove-btn:hover {
    opacity: 1;
}

/* Day/Night/Working Hour Color Coding */
.card.is-day { background: linear-gradient(135deg, #fefce8, #fff); }
.card.is-night { background: linear-gradient(135deg, #1e293b, #0f172a); color: var(--text-dark); }
.card.is-night .city-name { color: #818cf8; }
.card.is-night .country-name, .card.is-night .date-display, .card.is-night small, .card.is-night .tz-info span { color: #94a3b8; }
.card.is-night .timezone-details { border-top-color: #374151; }
.card.is-night .flag-emoji { filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.1)); }


.working-indicator {
    position: absolute;
    top: 0;
    right: 0;
    padding: 5px 8px;
    border-bottom-left-radius: 12px;
    border-top-right-radius: 12px;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
}

.working-indicator.green { background-color: var(--working-green); }
.working-indicator.yellow { background-color: var(--neutral-yellow); }
.working-indicator.red { background-color: var(--sleeping-red); }

/* Additional Global Controls */
.util-controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.util-controls button {
    flex-grow: 1;
    min-width: 150px;
}

/* --- BACKDROP --- */
#calendar-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(3px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    font-family: system-ui, sans-serif;
}

/* --- MODAL BOX (Zoho style) --- */
.calendar-modal-box {
    background: #ffffff;
    max-width: 420px;
    width: 100%;
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    animation: fadeIn .25s ease-out;
}

/* --- HEADER --- */
.calendar-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.calendar-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

#calendar-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    color: #6b7280;
    border-radius: 6px;
    transition: background 0.2s;
}
#calendar-modal-close:hover {
    background: #f0f0f0;
}

/* --- DESCRIPTION --- */
.calendar-modal-desc {
    margin: 0 0 16px;
    font-size: 14px;
    color: #4b5563;
}

/* --- BUTTONS LAYOUT --- */
.calendar-modal-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* --- ACTION BUTTON (Zoho style) --- */
.action-button {
    flex: 1;
    min-width: 120px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    background: #ffffff;
    font-size: 14px;
    color: #374151;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

/* Icon Wrapper (Zoho style) */
.btn-icon {
    background: #f3f4f6;
    padding: 6px;
    border-radius: 50%;
    display: flex;
}

.action-button:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

/* --- BRAND COLORS (subtle, not harsh) --- */
#cal-google .btn-icon i { color: #DB4437; }
#cal-outlook .btn-icon i { color: #1A73E8; }
#cal-ics .btn-icon i { color: #4b5563; }

/* --- NOTE --- */
.calendar-modal-note {
    margin-top: 16px;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.45;
}

/* --- ANIMATION --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}


/* Message Box Styling (for copy/errors) */
#message-box {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
    z-index: 1000;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

#message-box.show {
    opacity: 1;
    bottom: 30px;
}

/* Dark Mode Toggle Switch */
.toggle-switch-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
    color: var(--text-light); /* Default color for icons */
}
body.dark-mode .toggle-switch-container {
    color: var(--text-dark); /* Color for icons in dark mode */
}


.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.card * {
    pointer-events: none;
}

.remove-btn,
.edit-btn {
    pointer-events: auto;
}


/* Responsive Design */
@media (max-width: 768px) {
    .input-group, .time-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .util-controls {
        flex-direction: column;
    }
    .time-controls .input-item {
        flex-grow: 1;
    }
    .time-display {
        font-size: 2rem;
    }
    .card {
        padding: 15px;
    }
    .toggle-switch-container {
        top: 10px;
        right: 10px;
    }
}

/* Hidden input for calendar feature */
#calendar-form {
    display: none;
}
