* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    line-height: 1.6;
}

/* === СВЕТЛАЯ ТЕМА === */
body.light-theme {
    background-color: #fdf6e3;
    color: #002b36;
}

body.light-theme .container {
    background-color: #fffffe;
}

body.light-theme .section {
    background: #f8f4e8;
    border-color: #e0d8c8;
}

body.light-theme .section-title {
    color: #cb4b16;
}

body.light-theme input[type="range"] {
    background: #ddd;
}

body.light-theme input[type="number"],
body.light-theme input[type="time"],
body.light-theme select,
body.light-theme textarea {
    background: #f8f4e8;
    border-color: #e0d8c8;
    color: #002b36;
}

body.light-theme .theme-btn.dark {
    background: #2a2a2a;
    color: #fff;
}

body.light-theme .theme-btn.light {
    background: transparent;
    color: #657b83;
}

body.light-theme .theme-btn.active {
    background: #cb4b16 !important;
    color: #fff !important;
}

/* === КОНТЕЙНЕР === */
.container {
    max-width: 700px;
    margin: 0 auto;
    padding: 0 20px 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #2a2a2a;
    margin-bottom: 15px;
}

body.light-theme .header {
    border-bottom-color: #e0d8c8;
}

.header-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header h1 {
    font-size: 1.8rem;
    color: #ff9800;
}

body.light-theme .header h1 {
    color: #cb4b16;
}

.user-name {
    font-size: 0.85rem;
    color: #888;
}

body.light-theme .user-name {
    color: #657b83;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-link {
    color: #ff9800;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
}

.nav-link:hover {
    text-decoration: underline;
}

body.light-theme .nav-link {
    color: #cb4b16;
}

/* === ПЕРЕКЛЮЧАТЕЛЬ ТЕМЫ (кнопка с солнцем/луной) === */
.settings-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
    color: #e0e0e0;
}

.settings-btn:hover {
    background: #2a2a2a;
}

body.light-theme .settings-btn {
    color: #002b36;
}

body.light-theme .settings-btn:hover {
    background: #eee8d8;
}

.settings-btn .sun-icon {
    display: block;
}

.settings-btn .moon-icon {
    display: none;
}

/* В светлой теме показываем солнце, в тёмной - луну */
body:not(.light-theme) .settings-btn .sun-icon {
    display: none;
}

body:not(.light-theme) .settings-btn .moon-icon {
    display: block;
}

body.light-theme .settings-btn .sun-icon {
    display: block;
}

body.light-theme .settings-btn .moon-icon {
    display: none;
}

/* Старые стили (удалить позже) */
.theme-btn.dark {
    background: #1a1a1a;
    color: #fff;
}

.theme-btn.light {
    background: transparent;
    color: #888;
}

.theme-btn.active {
    background: #ff9800 !important;
    color: #fff !important;
}

/* === СЕКЦИИ === */
.section {
    background: #222;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid #333;
}

.section-warning {
    background: #2a1a1a;
    border-color: #4a2020;
}

body.light-theme .section {
    background: #f8f4e8;
    border-color: #e0d8c8;
}

body.light-theme .section-warning {
    background: #fff5f5;
    border-color: #ffcdd2;
}

.section-title {
    font-size: 1.1rem;
    color: #ff9800;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

body.light-theme .section-title {
    color: #cb4b16;
    border-bottom-color: #e0d8c8;
}

/* === ПОЛЯ === */
.field {
    margin-bottom: 20px;
}

.field:last-child {
    margin-bottom: 0;
}

.field label {
    display: block;
    margin-bottom: 8px;
    color: #aaa;
    font-size: 0.95rem;
}

body.light-theme .field label {
    color: #657b83;
}

.field .hint {
    font-size: 0.85rem;
    color: #888;
}

.field-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.field-inline {
    flex: 1;
}

.field-inline label {
    display: block;
    margin-bottom: 8px;
    color: #aaa;
    font-size: 0.95rem;
}

body.light-theme .field-inline label {
    color: #657b83;
}

/* === СЛАЙДЕРЫ === */
.slider-row {
    display: flex;
    align-items: center;
    gap: 15px;
}

input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #3a3a3a;
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: #ff9800;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: #ff9800;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.slider-value {
    min-width: 35px;
    text-align: center;
    font-weight: 600;
    font-size: 1.2rem;
    color: #ff9800;
}

body.light-theme .slider-value {
    color: #cb4b16;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 0.8rem;
    color: #666;
}

body.light-theme .slider-labels {
    color: #93a1a1;
}

/* === ИНПУТЫ === */
input[type="number"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 12px 15px;
    background: #2a2a2a;
    border: 2px solid #3a3a3a;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #ff9800;
}

input::placeholder,
textarea::placeholder {
    color: #666;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

textarea {
    resize: vertical;
    min-height: 60px;
}

/* === ПОЛЯ С ПРЕДУПРЕЖДЕНИЕМ === */
.field-warning select {
    border-color: #4a2020;
    background: #3a2020;
}

body.light-theme .field-warning select {
    border-color: #ef9a9a;
    background: #fff;
}

.field-safety select {
    border-color: #2a4a2a;
    background: #203a20;
}

body.light-theme .field-safety select {
    border-color: #a5d6a7;
    background: #fff;
}

/* === КНОПКИ === */
.form-actions {
    display: flex;
    justify-content: center;
    padding: 30px 0;
}

.btn-primary {
    background: #ff9800;
    color: #1a1a1a;
    border: none;
    padding: 14px 40px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

body.light-theme .btn-primary {
    background: #cb4b16;
    color: #fff;
}

.btn-primary:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 20px rgba(255, 152, 0, 0.3);
}

body.light-theme .btn-primary:hover {
    box-shadow: 0 4px 20px rgba(203, 75, 22, 0.3);
}

/* === УВЕДОМЛЕНИЕ === */
.notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #2a2a2a;
    color: #4caf50;
    padding: 14px 28px;
    border-radius: 25px;
    font-weight: 500;
    border: 1px solid #4caf50;
    z-index: 1000;
}

body.light-theme .notification {
    background: #fff;
    color: #2e7d32;
    border-color: #a5d6a7;
}

.hidden {
    display: none;
}

/* === MERGE DIALOG === */
.merge-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.merge-dialog-content {
    position: relative;
    background: #222;
    border: 1px solid #333;
    border-radius: 16px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.merge-dialog-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px 10px;
    line-height: 1;
}

.merge-dialog-close:hover {
    color: #fff;
}

body.light-theme .merge-dialog-close:hover {
    color: #002b36;
}

body.light-theme .merge-dialog-content {
    background: #fffffe;
    border-color: #e0d8c8;
}

.merge-dialog-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #ff9800;
    margin-bottom: 15px;
}

body.light-theme .merge-dialog-title {
    color: #cb4b16;
}

.merge-dialog-text {
    color: #aaa;
    margin-bottom: 25px;
    line-height: 1.5;
}

body.light-theme .merge-dialog-text {
    color: #657b83;
}

.merge-dialog-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.merge-btn {
    width: 100%;
    padding: 14px 20px;
    background: #333;
    border: 1px solid #444;
    border-radius: 10px;
    color: #e0e0e0;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.merge-btn:hover {
    background: #444;
    border-color: #555;
}

body.light-theme .merge-btn {
    background: #f8f4e8;
    border-color: #e0d8c8;
    color: #002b36;
}

body.light-theme .merge-btn:hover {
    background: #eee8d8;
    border-color: #ddd;
}

/* === SETTINGS DIALOG === */
.settings-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    padding: 20px;
}

.settings-dialog-content {
    position: relative;
    background: #222;
    border: 1px solid #333;
    border-radius: 16px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
}

body.light-theme .settings-dialog-content {
    background: #fffffe;
    border-color: #e0d8c8;
}

.settings-dialog-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px 10px;
    line-height: 1;
}

.settings-dialog-close:hover {
    color: #fff;
}

body.light-theme .settings-dialog-close:hover {
    color: #002b36;
}

.settings-dialog-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #ff9800;
    margin-bottom: 20px;
}

body.light-theme .settings-dialog-title {
    color: #cb4b16;
}

.settings-sections {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-item {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 10px;
    background: #2a2a2a;
    border-radius: 8px;
    transition: background 0.2s;
}

.settings-item:hover {
    background: #333;
}

body.light-theme .settings-item {
    background: #f8f4e8;
}

body.light-theme .settings-item:hover {
    background: #eee8d8;
}

.settings-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.settings-item span {
    color: #e0e0e0;
    font-size: 0.95rem;
}

body.light-theme .settings-item span {
    color: #002b36;
}

.settings-section {
    margin-bottom: 20px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #333;
}

body.light-theme .settings-section-title {
    color: #657b83;
    border-bottom-color: #e0d8c8;
}

.settings-section-header {
    margin-bottom: 10px;
}

.settings-section-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.settings-section-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.settings-section-checkbox .settings-section-title {
    margin: 0;
    padding: 0;
    border: none;
    font-size: 0.9rem;
    color: #e0e0e0;
}

body.light-theme .settings-section-checkbox .settings-section-title {
    color: #002b36;
}

.settings-item.hidden {
    display: none;
}

.settings-export-import {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
}

.settings-tab {
    flex: 1;
    padding: 10px 15px;
    background: #333;
    border: 1px solid #444;
    border-radius: 8px 8px 0 0;
    color: #888;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-tab.active {
    background: #444;
    color: #ff9800;
    border-bottom-color: #444;
}

body.light-theme .settings-tab {
    background: #f8f4e8;
    border-color: #e0d8c8;
    color: #657b83;
}

body.light-theme .settings-tab.active {
    background: #eee8d8;
    color: #cb4b16;
    border-bottom-color: #eee8d8;
}

.settings-tab-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.settings-tab-content.hidden {
    display: none;
}

.settings-list {
    overflow-y: auto;
}

.meds-list {
    overflow-y: auto;
}

.add-med-btn {
    margin-bottom: 15px;
}

.settings-export-import {
    display: flex;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid #333;
}

.med-item {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 15px;
}

body.light-theme .med-item {
    background: #f8f4e8;
    border-color: #e0d8c8;
}

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

.med-name-input {
    flex: 1;
    padding: 8px 12px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.95rem;
}

body.light-theme .med-name-input {
    background: #fff;
    border-color: #ddd;
    color: #002b36;
}

.med-delete-btn {
    background: transparent;
    border: none;
    color: #e53935;
    cursor: pointer;
    padding: 5px 10px;
    font-size: 1.2rem;
}

.med-delete-btn:hover {
    color: #ff5252;
}

.med-times {
    display: flex;
    gap: 10px;
}

.med-time-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.med-time-label {
    font-size: 0.8rem;
    color: #888;
}

body.light-theme .med-time-label {
    color: #657b83;
}

.med-time-input {
    width: 100%;
    padding: 8px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
    box-sizing: border-box;
}

body.light-theme .med-time-input {
    background: #fff;
    border-color: #ddd;
    color: #002b36;
}

.add-med-btn {
    width: 100%;
    padding: 12px;
    background: #333;
    border: 1px dashed #555;
    border-radius: 8px;
    color: #888;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.add-med-btn:hover {
    background: #3a3a3a;
    border-color: #666;
    color: #ff9800;
}

body.light-theme .add-med-btn {
    background: #f8f4e8;
    border-color: #ccc;
    color: #657b83;
}

body.light-theme .add-med-btn:hover {
    background: #eee8d8;
    border-color: #aaa;
    color: #cb4b16;
}

.med-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.med-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.med-item.med-inactive {
    opacity: 0.6;
}

.med-item.med-inactive .med-name-input {
    text-decoration: line-through;
}

/* Sleep records */
#sleep-records {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.sleep-record {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 15px;
}

body.light-theme .sleep-record {
    background: #f8f4e8;
    border-color: #e0d8c8;
}

.sleep-record-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.sleep-record-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-range-sep {
    color: #888;
    font-size: 1rem;
    padding: 0 4px;
}

body.light-theme .time-range-sep {
    color: #657b83;
}

.sleep-record-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #888;
}

body.light-theme .sleep-record-title {
    color: #657b83;
}

.sleep-record-delete {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 3px 8px;
    font-size: 1rem;
}

.sleep-record-delete:hover {
    color: #e53935;
}

.sleep-record-times {
    display: flex;
    gap: 10px;
}

.sleep-record-time {
    flex: 1;
}

.sleep-record-time label {
    display: block;
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 4px;
}

body.light-theme .sleep-record-time label {
    color: #657b83;
}

.sleep-record-time input {
    width: 100%;
    padding: 8px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
    box-sizing: border-box;
}

body.light-theme .sleep-record-time input {
    background: #fff;
    border-color: #ddd;
    color: #002b36;
}

.add-sleep-btn {
    width: 100%;
    padding: 10px;
    background: #333;
    border: 1px dashed #555;
    border-radius: 8px;
    color: #888;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 15px;
}

.add-sleep-btn:hover {
    background: #3a3a3a;
    border-color: #666;
    color: #ff9800;
}

body.light-theme .add-sleep-btn {
    background: #f8f4e8;
    border-color: #ccc;
    color: #657b83;
}

body.light-theme .add-sleep-btn:hover {
    background: #eee8d8;
    border-color: #aaa;
    color: #cb4b16;
}

.sleep-record .time-range {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 10px;
}

.sleep-record .time-range input {
    width: 110px;
    padding: 8px 10px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
    box-sizing: border-box;
    /* Remove spin buttons */
    -moz-appearance: textfield;
}

.sleep-record .time-range input::-webkit-outer-spin-button,
.sleep-record .time-range input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sleep-record .time-range span {
    color: #888;
}

body.light-theme .sleep-record .time-range input {
    background: #fff;
    border-color: #ddd;
    color: #002b36;
}

/* Basic time-range styles (for forms outside sleep-record) */
.field .time-range {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.field .time-range input {
    width: 110px;
    padding: 8px 10px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
    box-sizing: border-box;
    /* Remove spin buttons */
    -moz-appearance: textfield;
}

.field .time-range input::-webkit-outer-spin-button,
.field .time-range input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

body.light-theme .field .time-range input {
    background: #fff;
    border-color: #ddd;
    color: #002b36;
}

.field .time-range span {
    color: #888;
}

.export-import-btn {
    flex: 1;
    padding: 10px 15px;
    background: #333;
    border: 1px solid #444;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.export-import-btn:hover {
    background: #444;
    border-color: #555;
}

body.light-theme .export-import-btn {
    background: #f8f4e8;
    border-color: #e0d8c8;
    color: #002b36;
}

body.light-theme .export-import-btn:hover {
    background: #eee8d8;
    border-color: #ddd;
}

.gear-btn {
    margin-right: 8px;
}

.clear-data-wrapper {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #2a2a2a;
}

body.light-theme .clear-data-wrapper {
    border-top-color: #e0d8c8;
}

.clear-data-btn {
    width: 100%;
    padding: 12px 20px;
    background: #333;
    border: 1px solid #444;
    border-radius: 10px;
    color: #888;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-data-btn:hover {
    background: #3a3a3a;
    color: #e53935;
    border-color: #e53935;
}

body.light-theme .clear-data-btn {
    background: #f8f4e8;
    border-color: #e0d8c8;
    color: #657b83;
}

body.light-theme .clear-data-btn:hover {
    background: #eee8d8;
    color: #e53935;
    border-color: #e53935;
}
