:root {
    --bg: #ffffff;
    --text: #000000;
    --hint: #8e8e93;
    --accent: #007aff;
    --accent-text: #ffffff;
    --secondary-bg: #f2f2f7;
    --border: rgba(0, 0, 0, 0.1);
    --card-bg: #ffffff;
    --safe-area-bottom: env(safe-area-inset-bottom);
}

body.dark-mode {
    --bg: #000000;
    --text: #ffffff;
    --hint: #8e8e93;
    --accent: #0a84ff;
    --accent-text: #ffffff;
    --secondary-bg: #1c1c1e;
    --border: rgba(255, 255, 255, 0.1);
    --card-bg: #1c1c1e;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--secondary-bg);
    color: var(--text);
    overflow: hidden;
    user-select: none;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.ios-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background-color: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.ios-header h1 {
    margin: 0;
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

#selected-count {
    font-size: 20px;
    font-weight: 600;
    color: var(--accent);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Image Gallery */
.image-upload-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    margin-bottom: 5px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-cover: cover;
}

.gallery-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    backdrop-filter: blur(4px);
    z-index: 2;
}

.image-upload-actions {
    display: flex;
    gap: 10px;
}

.loading-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: var(--bg-secondary);
    border: 1px dashed var(--border);
}

.loading-item .spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.ios-btn-icon {
    background: var(--secondary-bg);
    color: var(--accent);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, background-color 0.2s;
}

.ios-btn-icon span {
    display: flex;
    line-height: 1;
    font-size: 22px;
}

.ios-btn-icon.danger {
    color: #ff3b30;
}

.ios-btn-icon:active {
    transform: scale(0.9);
}

/* Apple Style Card */
.apple-card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    transition: transform 0.2s, background-color 0.3s, opacity 0.3s, border 0.2s;
    position: relative;
    cursor: pointer;
    animation: slideIn 0.3s ease-out;
    user-select: none;
    -webkit-user-select: none;
    border: 2px solid transparent;
}

.apple-card.selected {
    border-color: var(--accent);
    background-color: var(--secondary-bg);
}

.apple-card.long-pressing {
    transform: scale(0.96);
    background-color: var(--secondary-bg);
}

.card-image-box {
    width: 60px;
    height: 60px;
    background: var(--secondary-bg);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.card-img-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-emoji {
    font-size: 28px;
}

.card-info {
    flex: 1;
}

.card-title {
    font-weight: 600;
    font-size: 17px;
    margin-bottom: 2px;
}

.card-meta {
    color: var(--hint);
    font-size: 14px;
}

.card-chevron {
    color: var(--hint);
    font-size: 18px;
}

/* Tabs */
.ios-tabs {
    position: fixed;
    bottom: 0;
    width: 100%;
    display: flex;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-area-bottom));
}

body.dark-mode .ios-tabs {
    background-color: rgba(0, 0, 0, 0.8);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--hint);
    cursor: pointer;
}

.tab-btn.active {
    color: var(--accent);
}

.tab-btn .icon {
    font-size: 22px;
}

.tab-btn .label {
    font-size: 10px;
    font-weight: 500;
}

/* Overlay / Panel */
.ios-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    transition: opacity 0.3s;
}

.ios-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.ios-panel {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 92%;
    background: var(--bg);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ios-overlay.hidden .ios-panel {
    transform: translateY(100%);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}

.ios-btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 17px;
    padding: 0;
    cursor: pointer;
}

.ios-btn-link.bold {
    font-weight: 600;
}

/* Form */
.ios-form {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 13px;
    text-transform: uppercase;
    color: var(--hint);
    margin-bottom: 8px;
    padding-left: 4px;
}

.form-group input, 
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 17px;
    outline: none;
}

.image-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--secondary-bg);
    border-radius: 14px;
}

#image-preview {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
}

.ios-btn-secondary {
    background: var(--bg);
    color: var(--accent);
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 500;
    font-size: 15px;
}

.hidden {
    display: none !important;
}

/* Settings */
.settings-section {
    margin-bottom: 32px;
}

.settings-group {
    background: var(--card-bg);
    border-radius: 14px;
    overflow: hidden;
}

.settings-item {
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-label {
    font-size: 17px;
}

/* Toggle Switch */
.ios-switch {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
}

.ios-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e9e9ea;
    transition: .4s;
    border-radius: 31px;
}

body.dark-mode .slider {
    background-color: #39393d;
}

.slider:before {
    position: absolute;
    content: "";
    height: 27px;
    width: 27px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

input:checked + .slider {
    background-color: #34c759;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.ios-btn-primary {
    width: 100%;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    padding: 16px;
    border-radius: 30px;
    font-size: 17px;
    font-weight: 600;
    margin-top: 10px;
}

/* Floating Bar */
#floating-bar {
    position: fixed;
    bottom: 90px;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    padding: 0 12px;
    pointer-events: none;
}

#floating-bar.hidden {
    display: none;
}

.floating-content {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: 100%;
    max-width: 440px;
    padding: 8px 12px;
    border-radius: 30px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
    border: 1px solid var(--border);
    gap: 8px;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#floating-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

@keyframes slideUpFade {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.floating-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.ios-btn-primary-small {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0 12px;
    height: 38px;
    border-radius: 19px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ios-btn-secondary-small {
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0 10px;
    height: 38px;
    border-radius: 19px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

#content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 160px; /* Запас для бара и табов */
    -webkit-overflow-scrolling: touch;
}

.ios-btn-primary-small:active, .ios-btn-secondary-small:active {
    transform: scale(0.96);
    opacity: 0.8;
}

.spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Undo Modal */
.undo-panel {
    height: 80vh !important;
}

.undo-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.undo-list-section {
    margin-top: 30px;
}

.undo-list-section h3 {
    font-size: 15px;
    text-transform: uppercase;
    color: var(--hint);
    margin-bottom: 12px;
}

.undo-items-list {
    background: var(--secondary-bg);
    border-radius: 14px;
    overflow: hidden;
}

.undo-item-row {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.undo-item-row:last-child {
    border-bottom: none;
}

.undo-item-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    border-radius: 6px;
}

.undo-item-info {
    flex: 1;
}

.undo-item-type {
    font-size: 12px;
    font-weight: 600;
}

.type-add { color: #34c759; }
.type-edit { color: #ff9500; }
.type-delete { color: #ff3b30; }

.undo-item-name {
    font-size: 15px;
    font-weight: 500;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--hint);
    font-size: 17px;
}

/* Featured Star Toggle */
.featured-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg);
    padding: 12px 16px;
    border-radius: 12px;
}

.rating-stars {
    display: flex;
    gap: 8px;
    padding: 12px 4px;
}

.rating-stars .star {
    font-size: 32px;
    color: #aaa;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rating-stars .star.active {
    color: #f5c542;
    text-shadow: 0 0 4px rgba(245, 197, 66, 0.4);
    transform: scale(1.1);
}

.rating-stars .star:active {
    transform: scale(0.9);
}

/* Star in list */
.card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: -8px;
}

.action-star {
    background: none;
    border: none;
    padding: 8px;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    color: #aaa;
    transition: transform 0.2s;
    position: relative;
}

.action-star.active {
    color: #f5c542;
}

.action-star[data-rating="2"]::after {
    content: "★";
    position: absolute;
    top: 4px;
    right: 0px;
    font-size: 14px;
}

.action-star[data-rating="3"]::after {
    content: "★★";
    position: absolute;
    top: 4px;
    right: -8px;
    font-size: 14px;
}

.action-star:active {
    transform: scale(1.2);
}

.action-delete-btn {
    background: none;
    border: none;
    padding: 8px;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    color: #ff3b30;
    opacity: 0.8;
}
