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

:root {
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-ghost: #dbeafe;
    --color-input-bg: #ffffff;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-danger: #ef4444;
    --color-danger-hover: #f87171;
    --color-text: #f3f4f6;
    --color-text-muted: #9ca3af;
    --color-border: #374151;
    --color-ghost: #1e3a5f;
    --color-input-bg: #111827;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow);
}

.theme-toggle {
    font-size: 1.25rem;
    transition: transform 0.3s;
}

.theme-toggle:hover { transform: scale(1.2); }

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--color-primary);
    text-decoration: none;
}

#app {
    max-width: 640px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

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

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

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

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

[data-theme="dark"] .btn-danger:hover { background: #371717; }

.btn-small { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    color: var(--color-text-muted);
    border-radius: 4px;
}

.btn-icon:hover { background: var(--color-bg); color: var(--color-text); }

/* Home */
.home {
    text-align: center;
    padding-top: 3rem;
}

.home h1 { font-size: 2.5rem; color: var(--color-primary); margin-bottom: 0.5rem; }
.home p { color: var(--color-text-muted); margin-bottom: 2rem; }

.home-open {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--color-border);
}

.home-open h3 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--color-text-muted); }

.inline-form {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.inline-form input { max-width: 250px; }

/* Forms */
form label {
    display: block;
    font-weight: 500;
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

form input[type="text"],
form input[type="password"],
form textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-input-bg);
    color: var(--color-text);
    transition: border-color 0.15s;
}

form input:focus, form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

form small { color: var(--color-text-muted); font-size: 0.75rem; }

.form-error { color: var(--color-danger); font-size: 0.875rem; margin-top: 0.5rem; min-height: 1.25rem; }

.form-page { background: var(--color-surface); padding: 1.5rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.form-page h2 { margin-bottom: 0.5rem; }
.form-page .btn-primary { margin-top: 1.5rem; width: 100%; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] { width: auto; }

/* List view */
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.list-header h2 { font-size: 1.5rem; }

.list-actions { display: flex; gap: 0.25rem; }

.item-list {
    list-style: none;
    margin-bottom: 1rem;
}

.item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
}

.item:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.12); }

.drag-handle {
    cursor: grab;
    color: var(--color-text-muted);
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.125rem;
    user-select: none;
    flex-shrink: 0;
}

.drag-handle:active { cursor: grabbing; }

.item-content {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.item-title {
    font-weight: 500;
    word-break: break-word;
}

.item-desc {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.9rem;
    line-height: 1.7;
}

.item-desc a { color: var(--color-primary); }
.item-desc code { background: var(--color-bg); padding: 0.125rem 0.375rem; border-radius: 3px; font-size: 0.85em; }
.item-desc pre { background: var(--color-bg); padding: 0.75rem; border-radius: var(--radius); overflow-x: auto; margin: 0.5rem 0; }
.item-desc pre code { background: none; padding: 0; }
.item-desc ul, .item-desc ol { padding-left: 1.5rem; }
.item-desc blockquote { border-left: 3px solid var(--color-border); padding-left: 0.75rem; color: var(--color-text-muted); margin: 0.5rem 0; }

.no-desc { color: var(--color-text-muted); }

.item-actions {
    display: flex;
    gap: 0.125rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.item:hover .item-actions { opacity: 1; }

/* On touch devices, always show actions */
@media (hover: none) {
    .item-actions { opacity: 1; }
}

.hidden { display: none !important; }

/* Sortable */
.sortable-ghost {
    background: var(--color-ghost);
    border-style: dashed;
    opacity: 0.7;
}

.sortable-chosen { box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

/* Add item form */
.add-item-form {
    display: flex;
    gap: 0.5rem;
}

.add-item-form input { flex: 1; }
.add-item-form .btn-primary { flex-shrink: 0; font-size: 1.25rem; padding: 0.5rem 0.875rem; }

/* Password prompt */
.password-prompt {
    text-align: center;
    padding-top: 3rem;
}

.password-prompt h2 { margin-bottom: 0.5rem; }
.password-prompt p { color: var(--color-text-muted); margin-bottom: 1.5rem; }
.password-prompt form { max-width: 300px; margin: 0 auto; }
.password-prompt input { text-align: center; margin-bottom: 0.5rem; }
.password-prompt .btn-primary { width: 100%; margin-top: 0.5rem; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.modal h3 { margin-bottom: 0.5rem; }

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* Messages */
.message { text-align: center; padding-top: 3rem; }
.message h2 { margin-bottom: 0.5rem; }
.message p { color: var(--color-text-muted); margin-bottom: 1rem; }
.message.error { color: var(--color-danger); }

.loading { text-align: center; padding-top: 3rem; color: var(--color-text-muted); }
