/* ============================================
   1. Reset & Variables
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.08);
    --primary-subtle: rgba(79, 70, 229, 0.05);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #fef2f2;
    --success: #22c55e;
    --warning: #f59e0b;

    --bg: #f1f5f9;
    --bg-subtle: #fafbfc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.10);
    --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.15);
    --shadow-primary: 0 4px 14px rgba(79, 70, 229, 0.35);
    --shadow-primary-hover: 0 6px 20px rgba(79, 70, 229, 0.45);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius: 8px;

    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-smooth: 300ms cubic-bezier(0.32, 0.72, 0, 1);
}

/* ============================================
   2. Base Typography & Body
   ============================================ */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   3. Auth Pages
   ============================================ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: linear-gradient(135deg, #f1f5f9 0%, #eef2ff 100%);
}

.auth-container {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.04),
        0 8px 24px rgba(0, 0, 0, 0.08);
    padding: 44px 40px 36px;
    width: 100%;
    max-width: 420px;
    animation: authFadeIn 0.4s ease both;
}

@keyframes authFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), #818cf8);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 14px;
    flex-shrink: 0;
}

.auth-container h1 {
    text-align: center;
    font-size: 23px;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin-bottom: 6px;
    color: var(--text);
}

.auth-container .subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 28px;
    line-height: 1.5;
}

/* ============================================
   4. Form Elements
   ============================================ */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    background: var(--card-bg);
    color: var(--text);
    line-height: 1.5;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-tertiary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* ============================================
   5. Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    line-height: 1.5;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
    padding: 12px 22px;
    font-size: 15px;
    border-radius: var(--radius-sm);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.btn-primary:active {
    transform: scale(0.99);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 7px 14px;
    font-size: 13px;
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 7px 14px;
    font-size: 13px;
    letter-spacing: 0;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: #fff;
}

.btn-cancel {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-cancel:hover {
    background: var(--border);
    color: var(--text);
}

/* ============================================
   6. Flash Messages
   ============================================ */
.flash-messages {
    margin-bottom: 20px;
}

.flash-message {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 8px;
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: 8px;
}

.flash-message.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.flash-message.danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.flash-message.warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.flash-message.info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* ============================================
   7. Auth Links
   ============================================ */
.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.auth-link a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* ============================================
   8. App Header
   ============================================ */
.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.92);
}

.app-header .logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
}

.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: var(--primary);
    color: #fff;
    font-size: 12px;
    flex-shrink: 0;
}

.app-header .user-info {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}

.app-header .user-info span {
    color: var(--text-secondary);
}

.app-header .user-info .username {
    color: var(--text);
    font-weight: 600;
}

/* ============================================
   9. Main Container
   ============================================ */
.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px;
    padding-bottom: 100px;
}

/* ============================================
   9b. Search Toggle Button
   ============================================ */
.search-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 6px;
    line-height: 1;
    transition: background var(--transition-fast);
    color: var(--text-secondary);
}

.search-toggle:hover {
    background: var(--bg);
    color: var(--primary);
}

/* ============================================
   9c. Collapsible Search Bar
   ============================================ */
.search-slide {
    height: 0;
    overflow: hidden;
    transition: height var(--transition-smooth);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.search-slide.active {
    height: 52px;
}

.search-slide-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    height: 52px;
    position: relative;
}

.search-slide-inner .search-icon {
    flex-shrink: 0;
    font-size: 14px;
    color: var(--text-tertiary);
}

.search-slide-inner input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: transparent;
    line-height: 1.5;
}

.search-slide-inner input::placeholder {
    color: var(--text-tertiary);
}

.search-close {
    flex-shrink: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
    line-height: 1;
}

.search-close:hover {
    background: var(--bg);
    color: var(--text-secondary);
}

/* ============================================
   10. Memo List & Cards
   ============================================ */
.memo-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memo-card {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px 12px 18px;
    cursor: pointer;
    transition: all var(--transition-base);
    overflow: hidden;
}

.memo-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 3px;
    background: var(--border);
    border-radius: 0 3px 3px 0;
    transition: background var(--transition-base), top var(--transition-base), bottom var(--transition-base);
}

.memo-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.10);
    transform: translateY(-1px);
}

.memo-card:hover::before {
    background: var(--primary);
    top: 0;
    bottom: 0;
}

.memo-card:active {
    transform: translateY(0);
    background: var(--bg-subtle);
}

.memo-card .memo-content {
    padding-right: 4px;
}

.memo-card .memo-event {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 6px;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    color: var(--text);
}

.memo-card .memo-time {
    font-size: 13px;
    color: var(--text-tertiary);
    line-height: 1.5;
}

.memo-card .memo-time .reltime-part {
    color: var(--primary);
    font-weight: 500;
}

/* ============================================
   11. Pagination
   ============================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 0 8px;
    flex-wrap: wrap;
}

.page-info {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-right: 8px;
    white-space: nowrap;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.page-btn:hover:not(:disabled):not(.active) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.page-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 500;
    cursor: default;
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-btn:active:not(:disabled):not(.active) {
    transform: scale(0.95);
}

/* ============================================
   12. Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: 72px 20px 60px;
}

.empty-state .empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-light);
    font-size: 28px;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 280px;
    margin: 0 auto;
}

/* ============================================
   13. FAB
   ============================================ */
.fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 26px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-primary);
    z-index: 100;
    transition: all var(--transition-base);
    line-height: 1;
}

.fab:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: var(--shadow-primary-hover);
}

.fab:active {
    transform: scale(0.95);
}

/* ============================================
   14. Bottom Sheet
   ============================================ */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 2000;
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.sheet-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card-bg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    z-index: 2001;
    transform: translateY(100%);
    transition: transform var(--transition-smooth);
    padding: 6px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.10);
}

.bottom-sheet.active {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #d4d8dd;
    margin: 6px auto 10px;
    flex-shrink: 0;
}

.sheet-header {
    padding: 8px 4px 14px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 6px;
}

.sheet-event {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    word-break: break-word;
    line-height: 1.45;
    color: var(--text);
}

.sheet-time {
    font-size: 13px;
    color: var(--text-secondary);
}

.sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 0;
}

.sheet-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 12px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition-fast);
    color: var(--text);
    text-align: left;
}

.sheet-btn:hover {
    background: var(--bg);
}

.sheet-btn:active {
    background: var(--border);
}

.sheet-btn-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.sheet-btn-danger {
    color: var(--danger);
}

.sheet-btn-danger:hover {
    background: var(--danger-light);
}

.sheet-cancel {
    display: block;
    width: 100%;
    padding: 14px;
    margin-top: 8px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg);
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    color: var(--text);
    text-align: center;
    transition: background var(--transition-fast);
}

.sheet-cancel:hover {
    background: var(--border);
}

/* ============================================
   15. Modal
   ============================================ */
.modal-overlay {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    padding: 24px;
    width: 100%;
    max-width: 440px;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.96) translateY(8px);
    transition: transform var(--transition-smooth), opacity var(--transition-base);
    opacity: 0;
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.modal h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.3px;
}

.modal .form-group {
    margin-bottom: 14px;
}

.modal .form-group textarea {
    min-height: 72px;
}

.time-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.time-row input {
    flex: 1;
}

.time-row input[readonly] {
    background: #f8fafc;
    cursor: default;
}

.live-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
    height: 40px;
}

.live-toggle:has(input:checked) {
    color: var(--primary);
}

.live-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
    outline: none;
    margin: 0;
    flex-shrink: 0;
}

.live-toggle input[type="checkbox"]:checked + span {
    color: var(--primary);
    font-weight: 500;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    justify-content: flex-end;
}

.modal-actions .btn {
    width: auto;
    min-width: 100px;
}

/* ============================================
   16. Loading State
   ============================================ */
.loading {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-tertiary);
    font-size: 14px;
}

/* ============================================
   17. Security Question Block
   ============================================ */
.security-question-block {
    font-size: 15px;
    padding: 12px 14px;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--text);
    line-height: 1.5;
    margin-top: 2px;
}

/* ============================================
   18. Remember Me Row (Auth)
   ============================================ */
.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
}

.remember-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.remember-row label {
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    font-weight: 400;
}

/* ============================================
   19. Responsive (max-width: 600px)
   ============================================ */
@media (max-width: 600px) {
    .auth-container {
        padding: 32px 22px 28px;
    }

    .auth-container h1 {
        font-size: 21px;
    }

    .app-header {
        padding: 0 16px;
        height: 52px;
    }

    .app-header .logo {
        font-size: 16px;
    }

    .app-main {
        padding: 16px;
        padding-bottom: 88px;
    }

    .search-slide-inner {
        padding: 8px 12px;
    }

    .memo-card {
        padding: 10px 14px 10px 16px;
    }

    .memo-card .memo-event {
        font-size: 16px;
    }

    .bottom-sheet {
        padding-left: 16px;
        padding-right: 16px;
    }

    .modal {
        padding: 24px 20px;
    }

    .modal h2 {
        font-size: 18px;
    }

    .time-row {
        flex-direction: column;
        align-items: stretch;
    }

    .fab {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .page-btn {
        min-width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .pagination {
        gap: 4px;
        padding: 16px 0 4px;
    }
}
