/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f8f7fc;
    --card-bg: #fff;
    --text: #1e1b4b;
    --text-secondary: #8b87a8;
    --accent: #4f46e5;
    --accent-light: #6366f1;
    --accent-bg: #eef2ff;
    --warm: #f59e0b;
    --warm-bg: #fffbeb;
    --danger: #ef4444;
    --border: #e8e5f0;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow: 0 4px 16px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* --- Top Bar --- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 20px rgba(79,70,229,0.25);
}

.top-bar .title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.3px;
    text-align: center;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 8px;
}

.icon-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.icon-btn:active { background: rgba(255,255,255,0.3); }

/* --- Main Content --- */
.main-content {
    padding: 16px;
    padding-bottom: calc(80px + var(--safe-bottom));
    max-width: 600px;
    margin: 0 auto;
}

/* --- Input Area --- */
.input-area {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    transition: box-shadow 0.3s;
}

.input-area:focus-within {
    box-shadow: var(--shadow-lg);
    border-color: #c7d2fe;
}

#record-input {
    width: 100%;
    border: none;
    resize: none;
    font-size: 15px;
    line-height: 1.7;
    outline: none;
    font-family: inherit;
    color: var(--text);
    min-height: 192px;
    overflow: hidden;
}

#record-input::placeholder { color: #c4b5d5; }

.btn-send {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}

.btn-send:active {
    transform: scale(0.97);
    box-shadow: 0 1px 4px rgba(79,70,229,0.2);
}

.btn-send:disabled {
    opacity: 0.55;
    transform: none;
}

/* --- Feed --- */
.feed { display: flex; flex-direction: column; gap: 12px; }

.feed-item {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    animation: fadeIn 0.35s ease-out;
}

.feed-item[data-type="record"] {
    cursor: pointer;
    transition: transform 0.15s;
}

.feed-item[data-type="record"]:active {
    transform: scale(0.98);
    background: #faf9fe;
}

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

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

.feed-item .item-badge {
    font-size: 10px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-record {
    background: var(--accent-bg);
    color: var(--accent);
}

.badge-summary {
    background: var(--warm-bg);
    color: #d97706;
}

.feed-item .item-time {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.feed-item .item-content {
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    color: #374151;
}

/* --- Markdown Content --- */
.md-content {
    white-space: normal !important;
}
.md-content h1 { font-size: 20px; color: var(--accent); margin: 16px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); }
.md-content h2 { font-size: 17px; color: var(--accent-light); margin: 14px 0 8px; padding-left: 10px; border-left: 3px solid var(--accent-light); }
.md-content h3 { font-size: 15px; color: #7c3aed; margin: 12px 0 6px; }
.md-content h4 { font-size: 14px; color: #8b5cf6; margin: 10px 0 4px; }
.md-content h5 { font-size: 13px; color: #a78bfa; margin: 8px 0 4px; }
.md-content p { margin: 8px 0; }
.md-content ul, .md-content ol { margin: 8px 0; padding-left: 20px; }
.md-content li { margin: 4px 0; }
.md-content blockquote {
    border-left: 3px solid #d1d5db;
    margin: 10px 0;
    padding: 6px 12px;
    background: #f9fafb;
    color: #6b7280;
    font-style: italic;
}
.md-content strong { color: var(--accent); font-weight: 600; }
.md-content em { color: #6b7280; }
.md-content code {
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 3px;
    font-family: Consolas, Monaco, monospace;
    font-size: 90%;
}

.feed-item .summary-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.feed-item .summary-section:first-of-type {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.feed-item .summary-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    display: inline-block;
    background: var(--accent-bg);
    padding: 2px 8px;
    border-radius: 4px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 48px 0;
    font-size: 14px;
}

/* --- Inline Confirm --- */
.feed-item.is-confirming {
    background: #fef2f2;
    border-color: #fecaca;
    text-align: center;
}

.confirm-text {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 12px;
    font-weight: 500;
}

.item-actions {
    display: flex;
    gap: 10px;
}

.item-actions button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-cancel-inline {
    background: var(--bg);
    color: var(--text-secondary);
}

.btn-confirm-delete-inline {
    background: var(--danger);
    color: #fff;
}

/* --- Panels (Overlays) --- */
.panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.panel-overlay.active {
    visibility: visible;
    opacity: 1;
}

.panel {
    position: fixed;
    top: 0;
    width: 88%;
    max-width: 400px;
    height: 100%;
    background: var(--bg);
    z-index: 101;
    display: flex;
    flex-direction: column;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.panel-left {
    left: 0;
    transform: translateX(-100%);
    border-right: 1px solid var(--border);
}

.panel-left.active { transform: translateX(0); }

.panel-right {
    right: 0;
    transform: translateX(100%);
    border-left: 1px solid var(--border);
}

.panel-right.active { transform: translateX(0); }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.panel-header .icon-btn {
    background: var(--bg);
    color: var(--text);
    border-radius: 10px;
}

.panel-header .icon-btn:active { background: var(--border); }

.panel-body {
    padding: 18px;
    flex: 1;
    overflow-y: auto;
}

.panel-body label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 14px 0 6px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.panel-body label:first-child { margin-top: 0; }

.panel-body textarea,
.panel-body input {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-bg);
}

.panel-body textarea:focus,
.panel-body input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.btn-save {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding: 12px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
    transition: transform 0.15s;
}

.btn-save:active { transform: scale(0.97); }

.btn-logout {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding: 12px;
    background: var(--card-bg);
    color: var(--danger);
    border: 1.5px solid #fecaca;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-logout:active { background: #fef2f2; }



.setting-msg {
    margin-top: 12px;
    font-size: 13px;
    text-align: center;
    font-weight: 500;
}

.setting-msg.success { color: #059669; }
.setting-msg.error { color: var(--danger); }

.panel-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 22px 0 0;
}

/* --- Search --- */
.search-box { margin-bottom: 14px; }

#search-input {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-bg);
}

#search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.quick-dates {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-date {
    flex: 1;
    padding: 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-date:active { background: var(--accent-bg); }
.btn-date.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}

/* --- Login --- */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: linear-gradient(180deg, #f8f7fc 0%, #eef2ff 100%);
}

.login-title {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 36px;
    font-size: 15px;
}

.login-form {
    width: 100%;
    max-width: 320px;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    outline: none;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-bg);
}

.login-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    margin-top: 12px;
    font-weight: 500;
}

.btn-login {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding: 14px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(79,70,229,0.35);
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-login:active {
    transform: scale(0.97);
    box-shadow: 0 2px 8px rgba(79,70,229,0.2);
}
