:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-card: rgba(28, 30, 43, 0.75);
    --bg-card-hover: #242636;
    --bg-input: #12141e;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --danger: #ef4444;
    --border: #2a2d3e;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Header */
header {
    padding: 1.5rem 2rem 0.5rem;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
}

.banner-wrap {
    text-align: center;
    overflow: hidden;
}

.banner-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
}

.ascii-banner {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.65rem;
    line-height: 1.15;
    color: var(--accent);
    margin: 0 auto;
    user-select: none;
    display: inline-block;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
}

.banner-datetime {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    letter-spacing: 0.05em;
}

.search-wrap {
    max-width: 400px;
    margin: 0.75rem auto 0;
}

.search-wrap input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 2rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    text-align: center;
}

.search-wrap input:focus {
    border-color: var(--accent);
}

.search-wrap input::placeholder {
    color: var(--text-muted);
}

/* Search match highlighting */
.widget.search-hidden {
    display: none;
}

.search-highlight {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 2px;
}

.edit-badge {
    position: absolute;
    top: 1.5rem;
    right: 2rem;
}

/* Grid — flex-wrap so widgets are independently sized */
.widget-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    padding: 1.25rem 2rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    align-items: flex-start;
}

/* Widget cards */
.widget {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: border-color 0.15s ease;
    width: 350px;
    flex-shrink: 0;
    flex-grow: 0;
}

.widget:hover {
    border-color: #363950;
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    min-height: 2.75rem;
}

.widget-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.widget-controls {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.widget-body {
    padding: 1rem;
}

/* Item icon */
.item-icon {
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
    width: 1.25rem;
    text-align: center;
}

/* Bookmark group */
.bookmark-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    margin: 0 -0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.bookmark-item:hover {
    background: var(--bg-card-hover);
}

.bookmark-item a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.15s;
    flex: 1;
    min-width: 0;
}

.bookmark-item a:hover {
    color: var(--accent-hover);
}

/* App pin */
.app-pin-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.app-pin-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    margin: 0 -0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.app-pin-item:hover {
    background: var(--bg-card-hover);
}

.app-pin-link {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    padding: 0.375rem 0;
    flex: 1;
    min-width: 0;
}

.app-pin-link:hover .app-name {
    color: var(--accent-hover);
}

.app-name {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: color 0.15s;
}

.app-description {
    color: var(--text-muted);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Reading list */
.reading-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.reading-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    margin: 0 -0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.reading-item:hover {
    background: var(--bg-card-hover);
}

.reading-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.reading-item a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reading-item a:hover {
    color: var(--accent-hover);
}

.reading-item.read a {
    color: var(--text-muted);
}

/* Quick notes */
.notes-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

.notes-content {
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.notes-editor {
    width: 100%;
    min-height: 120px;
    resize: vertical;
    font-family: var(--font);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Todo list */
.todo-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.todo-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    margin: 0 -0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.todo-item:hover {
    background: var(--bg-card-hover);
}

.todo-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.todo-text {
    font-size: 0.9rem;
}

.line-through {
    text-decoration: line-through;
}

/* Forms */
input, textarea, select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    font-family: var(--font);
    font-size: 0.875rem;
    width: 100%;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
    cursor: pointer;
}

input[type="color"] {
    width: 100%;
    padding: 0.125rem;
    height: 3rem;
    cursor: pointer;
}

select {
    cursor: pointer;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
}

.form-row .form-group {
    flex: 1;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.color-picker-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-input {
    flex: 1;
}

.add-item-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.add-item-form input {
    flex: 1;
    min-width: 0;
}

.input-icon {
    max-width: 3rem;
    flex: 0 0 3rem !important;
    text-align: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

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

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

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

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

.btn-icon {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

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

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

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

.btn-add-widget {
    width: 100%;
    padding: 1rem;
    background: transparent;
    border: 2px dashed var(--border);
    color: var(--text-muted);
    font-size: 0.9rem;
    border-radius: var(--radius);
}

.btn-add-widget:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(99, 102, 241, 0.05);
}

/* Utility */
.text-muted {
    color: var(--text-muted);
}

/* Add widget area */
.add-widget-area {
    width: 100%;
}

/* Data import/export */
.data-actions {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    padding-top: 0.75rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.import-form {
    display: inline-flex;
}

.import-label {
    cursor: pointer;
}

/* Resizable widgets in edit mode */
.widget[data-widget-id] {
    resize: both;
    overflow: auto;
    min-width: 200px;
    min-height: 120px;
}

/* Snap guide lines shown during resize */
.snap-guide-v {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--accent);
    opacity: 0.3;
    pointer-events: none;
    z-index: 999;
}

/* Item actions (edit/delete buttons) */
.item-actions {
    display: flex;
    gap: 0.125rem;
    flex-shrink: 0;
}

/* Inline edit item form */
.edit-item-form {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: wrap;
    align-items: center;
}

.edit-item-form input {
    flex: 1;
    min-width: 0;
}

/* HTMX transitions */
.htmx-swapping {
    opacity: 0.5;
    transition: opacity 150ms ease;
}

/* Responsive */
@media (max-width: 768px) {
    .ascii-banner {
        font-size: 0.3rem;
    }
}

@media (max-width: 640px) {
    header {
        padding: 1.25rem 1rem 0.25rem;
    }

    .widget-grid {
        padding: 1rem;
        gap: 1rem;
    }

    .widget {
        width: 100% !important;
    }

    .edit-badge {
        position: static;
        display: block;
        text-align: center;
        margin-top: 0.5rem;
    }
}
