/* --- Загальні налаштування та змінні --- */
:root {
    --panel-offset: 100px;
    --tile-border-color: rgba(255, 255, 255, 0.3);
    --text-color-light: #f0f0f0;
    --text-color-dark: #333;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

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

body {
    margin: 0;
    padding: 20px;
    font-family: 'Manrope', sans-serif;
    background: linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%);
    color: var(--text-color-dark);
    min-height: 100vh;
}

body.dark-theme {
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    color: var(--text-color-light);
}

/* --- Верхня панель --- */
.top-bar { display: flex; justify-content: center; align-items: center; height: 44px; margin-bottom: 16px; color: white; font-size: 1.2rem; }
.theme-switcher-wrapper { display: flex; align-items: center; gap: 10px; padding: 8px 15px; background: rgba(0, 0, 0, 0.2); border-radius: 20px; font-size: 1.2rem;}
.top-bar { position: relative; }
.settings-gear { position: absolute; right: 0; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(0,0,0,.15); color: var(--text-color-dark); font-size: 28px; cursor: pointer; }
.dark-theme .settings-gear { color: var(--text-color-light); }
.settings-dialog { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-sizing: border-box; margin: auto; padding: 24px; border: 1px solid #7c8c91; border-radius: 20px; background: #edf3ef; color: #203039; font: inherit; overflow-y: auto; }
.dark-theme .settings-dialog { background: #20343d; color: #eef2f3; }
.settings-dialog::backdrop { background: rgba(0,0,0,.6); }
.settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.settings-heading h2 { font-size: 1.2rem; margin: 0; }
.settings-dialog form, #settings-form { display: grid; gap: 12px; }
.settings-dialog form[hidden], #settings-form[hidden] { display: none; }
.settings-dialog .settings-secondary { background: transparent; border: 1px solid #87999f; color: inherit; }
.settings-dialog [hidden] { display: none; }
.settings-dialog input { width: 100%; box-sizing: border-box; border: 1px solid #87999f; padding: 10px; border-radius: 8px; font: inherit; background: #fff; color: #17262c; }
.settings-dialog button { border: 0; border-radius: 8px; padding: 10px 14px; background: #91c8ff; color: #142b40; font: inherit; cursor: pointer; }
.settings-dialog button:disabled { opacity: .6; cursor: wait; }
.settings-dialog p { margin: 0; }
#settings-message { margin-top: 14px; font-size: .9rem; }
.settings-dialog input[type="range"] { padding: 0; border: 0; background: transparent; accent-color: #149c76; cursor: pointer; min-height: 32px; }
#alert-volume-hint { font-size: .8rem; opacity: .8; }
.settings-checkbox { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.settings-dialog .theme-switcher input { width: 0; height: 0; padding: 0; border: 0; }
.settings-dialog .theme-switcher input:focus-visible + .slider { outline: 2px solid #589fe8; outline-offset: 2px; }
#alert-loop-hint { font-size: .8rem; opacity: .8; }
.sound-toggle[hidden] { display: none; }
.theme-switcher { position: relative; display: inline-block; width: 44px; height: 24px; }
.theme-switcher 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: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #8ec5fc; }
input:checked + .slider:before { transform: translateX(20px); }

/* --- Обгортка сторінки --- */
.page-wrapper {
    width: 100%;
    max-width: 2200px;
    margin: 0 auto;
}

/* --- ОСНОВНИЙ КОНТЕЙНЕР --- */
.main-container {
    display: grid;
    /* The map gets remaining space; side panels shrink with the viewport. */
    grid-template-columns: clamp(220px, 22vw, 490px) minmax(0, 1fr) clamp(220px, 18vw, 340px);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px;
    height: calc(100vh - var(--panel-offset));
    height: calc(100dvh - var(--panel-offset));
}

/* --- Стилі плиток --- */
.tile {
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--tile-border-color);
    border-radius: 24px;
    padding: 25px;
    box-shadow: 0 8px 32px 0 var(--shadow-color);
    display: flex;
    flex-direction: column;
}

/* --- Розміщення плиток по сітці --- */
.tile-weather { grid-column: 1; grid-row: 1; }
.tile-time { grid-column: 1; grid-row: 2; }
.tile-map {
    grid-column: 2;
    grid-row: 1 / 3;
    height: calc(100vh - var(--panel-offset));
    height: calc(100dvh - var(--panel-offset));
    padding: clamp(10px, 2vh, 25px);
}
.tile-map .tile-title, .tile-map .tile-footer, .tile-map .alerts-updated { flex-shrink: 0; }
.tile-news { grid-column: 3; grid-row: 1 / 3; }

/* Кольори плиток */
.tile-weather { background-color: rgba(251, 194, 235, 0.2); }
.tile-time { background-color: rgba(170, 193, 238, 0.2); }
.tile-map { background-color: rgba(255, 255, 255, 0.15); }
.tile-news {
    /* Avoid backdrop repaint artifacts next to the live map iframe. */
    background-color: #d8e6dd;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    isolation: isolate;
    contain: paint;
}

body.dark-theme .tile { --tile-border-color: rgba(255, 255, 255, 0.1); }
body.dark-theme .tile-weather { background-color: rgba(251, 194, 235, 0.05); }
body.dark-theme .tile-time { background-color: rgba(170, 193, 238, 0.05); }
body.dark-theme .tile-map { background-color: rgba(0, 0, 0, 0.2); }
body.dark-theme .tile-news { background-color: #244349; }

.tile-title { margin: 0 0 20px 0; font-size: 1.1rem; font-weight: 700; opacity: 0.7; }
.tile .content { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; overflow: hidden; }

/* --- Вміст плиток --- */
.weather-temp { font-size: 8rem; font-weight: 800; line-height: 1; }
.time-display {
    font-size: 6rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.date-display, .weekday-display { font-size: 1.5rem; opacity: 0.7; margin-top: 10px; }

.map-container { position: relative; flex: 1 1 0; min-height: 0; border-radius: 12px; overflow: hidden; margin-bottom: 12px; }
.map-container iframe { display: block; width: 100%; height: 100%; border: none; }
.map-view-toggle { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; background: #e9eaed; color: #555; cursor: pointer; }
.dark-theme .map-view-toggle { background: #14191e; color: #a0a4a8; }
.map-view-toggle[hidden] { display: none; }
.map-view-toggle:hover { color: #111; }
.dark-theme .map-view-toggle:hover { color: #fff; }
.map-view-toggle:focus-visible { outline: 2px solid #589fe8; outline-offset: -2px; }
.map-view-toggle .map-collapse-icon, .map-view-toggle.is-expanded .map-expand-icon { display: none; }
.map-view-toggle.is-expanded .map-collapse-icon { display: block; }

/* --- СТИЛІ ДЛЯ БЛОКУ НОВИН --- */
.tile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.tile-header .tile-title {
    margin-bottom: 0;
}
.refresh-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.6;
    padding: 0;
    transition: opacity 0.2s, transform 0.3s;
}
.refresh-btn:hover {
    opacity: 1;
}
.refresh-btn.loading {
    transform: rotate(360deg);
    transition: transform 0.5s linear;
}
#news-content {
    overflow-y: auto;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 15px;
    justify-content: flex-start;
    padding-right: 10px;
}
.news-item {
    display: block;
    padding: 10px;
    border-radius: 12px;
    background: rgba(0,0,0,0.1);
    text-decoration: none;
    color: inherit;
    transition: background 0.3s;
}
.news-item:hover {
    background: rgba(0,0,0,0.2);
}
.news-title {
    font-weight: 700;
    margin-bottom: 5px;
}
.news-snippet {
    font-size: 0.9rem;
    opacity: 0.8;
    line-height: 1.4;
}
body.dark-theme .news-item {
    background: rgba(255,255,255,0.05);
}
body.dark-theme .news-item:hover {
    background: rgba(255,255,255,0.1);
}

/* --- СТИЛІ ДЛЯ КАСТОМНОГО СКРОЛУ В БЛОЦІ НОВИН --- */
#news-content::-webkit-scrollbar {
  width: 6px;
}
#news-content::-webkit-scrollbar-track {
  background: transparent;
}
#news-content::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}
#news-content::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.5);
}


/* --- Футер та кнопки --- */
.tile-footer { display: flex; justify-content: center; align-items: center; gap: 20px; padding-top: 20px; }
.alert-footer { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding-top: 0; }
.alert-status { flex-grow: 1; padding: 10px; border-radius: 12px; text-align: center; font-weight: 700; color: white; transition: background-color 0.5s ease; }
.alert-status.status-yellow { background-color: #f4c542; color: #29220c; }
.alert-status.status-red { background-color: #b92c35; color: #fff; }
.alert-status.status-unknown { background-color: #525b65; color: #fff; }
.alert-status.status-inactive { background-color: #5cb85c; }
.sound-toggle { background-color: rgba(255, 255, 255, 0.2); border: 1px solid var(--tile-border-color); color: inherit; padding: 8px 16px; border-radius: 20px; cursor: pointer; font-family: 'Manrope', sans-serif; font-size: 0.9rem; transition: all 0.2s; flex-shrink: 0; }
.sound-toggle:hover { background-color: rgba(255, 255, 255, 0.4); }
body.dark-theme .sound-toggle { background-color: rgba(0, 0, 0, 0.2); }
body.dark-theme .sound-toggle:hover { background-color: rgba(0, 0, 0, 0.4); }

/* --- Нижній блок тривог --- */
.other-alerts-footer {
    margin-top: 20px;
    padding: 20px 25px;
    background-color: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--tile-border-color);
    border-radius: 24px;
    box-shadow: 0 8px 32px 0 var(--shadow-color);
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

body.dark-theme .other-alerts-footer { background-color: rgba(0, 0, 0, 0.2); }
.other-alerts-footer h4 { margin: 0; font-size: 1.1rem; font-weight: 700; opacity: 0.7; margin-right: 10px; }
.alert-badge { background-color: rgba(0, 0, 0, 0.1); padding: 6px 12px; border-radius: 12px; font-size: 0.9rem; font-weight: 500; }
body.dark-theme .alert-badge { background-color: rgba(255, 255, 255, 0.1); }
.alert-badge.level-yellow, body.dark-theme .alert-badge.level-yellow { background-color: #f4c542; color: #29220c; }
.alert-badge.level-red, body.dark-theme .alert-badge.level-red { background-color: #b92c35; color: #fff; }
.alert-badge.level-unknown, body.dark-theme .alert-badge.level-unknown { background-color: #525b65; color: #fff; }

/* --- Адаптивність --- */
@media (max-width: 1200px) {
    .main-container {
        display: flex;
        flex-direction: column;
        height: auto;
    }
}
#audio-status { flex-shrink: 0; font-size: .8rem; line-height: 1.3; max-height: 2.6em; overflow-y: auto; margin-top: 8px; }
#audio-status:empty { display: none; }
.alerts-updated { font-size: .85rem; margin-bottom: 12px; opacity: .8; }
.tile { min-width: 0; min-height: 0; }
.tile-weather, .tile-time { overflow: visible; }
.tile-weather, .tile-time { container-type: inline-size; }
.tile-weather .content, .tile-time .content {
  flex-shrink: 0;
  overflow: visible;
  padding-block: 8px;
}
.tile-weather .tile-title, .tile-weather .tile-footer { flex-shrink: 0; }
.weather-temp {
  font-size: 3rem;
  line-height: 1.3;
  white-space: nowrap;
  flex-shrink: 0;
}
.time-display { font-size: 2rem; line-height: 1.3; white-space: nowrap; flex-shrink: 0; }
@supports (font-size: 1cqi) {
  .time-display { font-size: min(6rem, 22cqi); }
  .weather-temp { font-size: min(8rem, 32cqi); }
}
.tile-footer { flex-wrap: wrap; }
@media (min-width: 1201px) {
  .tile-weather, .tile-time {
    container-type: size;
    padding: clamp(8px, 1.8vh, 25px);
  }
  .tile-weather .tile-title, .tile-time .tile-title {
    font-size: clamp(12px, 6cqb, 1.1rem);
    line-height: 1.2;
    margin-bottom: clamp(4px, 3cqb, 12px);
    flex-shrink: 0;
  }
  .tile-weather .content, .tile-time .content {
    min-height: 0;
    flex: 1 1 0;
    padding-block: 4px;
  }
  .weather-temp { font-size: min(8rem, 32cqi, max(1rem, calc((100cqb - 100px) / 1.3))); }
  .time-display { font-size: min(6rem, 22cqi, max(1rem, calc((100cqb - 100px) / 1.3))); }
  .tile-time .date-display, .tile-time .weekday-display {
    font-size: clamp(12px, min(6cqi, 8cqb), 1.5rem);
    line-height: 1.3;
    margin-top: clamp(3px, 2cqb, 10px);
  }
  .tile-weather .tile-footer {
    gap: 8px;
    padding-top: clamp(4px, 3cqb, 12px);
    flex-wrap: nowrap;
  }
  .tile-weather .sound-toggle {
    min-width: 0;
    flex-shrink: 1;
    padding: 6px 8px;
    font-size: clamp(10px, 3.5cqi, .9rem);
  }
  .tile-weather .theme-switcher-wrapper { gap: 4px; padding: 4px 6px; font-size: .8rem; }
}
@media (max-width: 1200px) {
  .weather-temp { font-size: clamp(3rem, 5.5vw, 8rem); }
  .time-display { font-size: clamp(2rem, 3.75vw, 6rem); }
  .tile-map { order: -1; flex: none; }
  #news-content { max-height: 500px; }
}
@media (max-width: 480px) {
  :root { --panel-offset: 80px; }
  body { padding: 10px; }
  .tile { padding: 16px; }
  .tile-map { padding: 12px; }
  .alert-footer { flex-direction: column; align-items: stretch; }
}
@media (max-height: 600px) {
  .tile-map { padding: 10px; }
  .tile-map .tile-title { font-size: .9rem; margin-bottom: 8px; }
  .tile-map .map-container { margin-bottom: 6px; }
  .tile-map .alerts-updated { font-size: .75rem; margin-bottom: 6px; }
  .tile-map .alert-footer { gap: 6px; }
  .tile-map .alert-status { font-size: .8rem; padding: 6px; }
  .tile-map .sound-toggle { font-size: .75rem; padding: 6px 10px; }
}

.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-row .theme-switcher { flex: none; }
.settings-dialog input[type="number"]:disabled { opacity: .5; }
.refresh-btn[hidden] { display: none; }
/* Settings dialog scrollbar in the dashboard palette */
.settings-dialog { scrollbar-width: thin; scrollbar-color: #7c8c91 transparent; }
.dark-theme .settings-dialog { scrollbar-color: #4f6a74 transparent; }
.settings-dialog::-webkit-scrollbar { width: 8px; }
.settings-dialog::-webkit-scrollbar-track { background: transparent; margin: 16px 0; }
.settings-dialog::-webkit-scrollbar-thumb { background: #9fb0b5; border-radius: 8px; }
.dark-theme .settings-dialog::-webkit-scrollbar-thumb { background: #4f6a74; }
.settings-dialog::-webkit-scrollbar-thumb:hover { background: #149c76; }
.settings-dialog::-webkit-scrollbar-button { display: none; height: 0; }
