:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #dde1e6;
    --color-text: #1f2430;
    --color-muted: #6b7280;
    --color-primary: #3b5bdb;
    --color-primary-dark: #2f4bc0;
    --color-danger: #d64545;
    --color-success: #2f9e44;
    --radius: 6px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; }

/* Nav */
.topnav { background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.topnav-bar { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.5rem; }
.topnav-brand { font-weight: 700; }
.nav-toggle {
    display: none;
    background: none; border: none; font-size: 1.3rem; line-height: 1;
    cursor: pointer; color: var(--color-text); padding: 0.25rem 0.5rem;
}
.topnav-collapse { display: flex; align-items: center; padding: 0 1.5rem 0.75rem; gap: 1.25rem; }
.topnav-links { display: flex; gap: 1.25rem; flex: 1; flex-wrap: wrap; }
.topnav-links a { color: var(--color-muted); }
.topnav-links a.active { color: var(--color-primary); font-weight: 600; }
.topnav-user { display: flex; align-items: center; gap: 1rem; color: var(--color-muted); font-size: 0.9rem; white-space: nowrap; }

/* Page */
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.toolbar { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 0.4rem 0.6rem; border: 1px solid var(--color-border); border-radius: var(--radius); }

.tabs { display: flex; gap: 0.5rem; }
.tab {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    border-radius: 999px;
    cursor: pointer;
    color: var(--color-muted);
}
.tab.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* Buttons */
.btn {
    background: var(--color-primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
}
.btn:hover { background: var(--color-primary-dark); }
.btn-secondary { background: transparent; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: #eceef1; }
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: #b93333; }
.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-muted);
    padding: 0.25rem 0.5rem;
}
.btn-icon:hover { color: var(--color-text); }

/* Table */
.data-table { width: 100%; min-width: 560px; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
.data-table th { color: var(--color-muted); font-weight: 600; background: #fafbfc; }
.data-table td.empty { text-align: center; color: var(--color-muted); padding: 2rem; }
.data-table tr:last-child td { border-bottom: none; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    margin: 0 0.25rem 0.25rem 0;
}
.tag-chip button { border: none; background: none; cursor: pointer; color: inherit; font-weight: 700; padding: 0; }

.swatch { display: inline-block; width: 1.2rem; height: 1.2rem; border-radius: 4px; border: 1px solid var(--color-border); vertical-align: middle; }

/* Alerts */
.alert { padding: 0.6rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-error { background: #fdecec; color: #a12b2b; border: 1px solid #f5c2c2; }
.alert-success { background: #e9f8ee; color: #216e37; border: 1px solid #b7e6c4; }
.alert-info { background: #eaf1ff; color: #29457a; border: 1px solid #c3d6f7; }

/* Modal */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 3rem 1rem; overflow-y: auto; z-index: 100;
}
.modal-box {
    background: var(--color-surface); border-radius: var(--radius);
    padding: 1.5rem; width: 100%; max-width: 480px;
}
.modal[hidden] { display: none; }

form label { display: block; margin-bottom: 0.85rem; font-size: 0.85rem; color: var(--color-muted); }
form label.checkbox { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
form label.checkbox input { width: auto; }
form input[type=text], form input[type=email], form input[type=password], form input[type=url],
form textarea, form select {
    width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--color-border);
    border-radius: var(--radius); font-size: 0.95rem; margin-top: 0.3rem; font-family: inherit;
}
form input[type=color] { margin-top: 0.3rem; width: 100%; height: 2.2rem; padding: 0.2rem; }
.form-row { display: flex; gap: 1rem; }
.form-row > label { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.hint { font-weight: 400; font-size: 0.78rem; }

.tag-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.tag-picker .tag-chip { cursor: pointer; opacity: 0.55; border: 1px solid var(--color-border); }
.tag-picker .tag-chip.selected { opacity: 1; }

#item-comments-list { max-height: 160px; overflow-y: auto; margin-bottom: 0.5rem; }
.comment { padding: 0.4rem 0; border-bottom: 1px solid var(--color-border); font-size: 0.85rem; }
.comment-meta { color: var(--color-muted); font-size: 0.75rem; }

/* Login / Install */
.login-body, .install-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { background: var(--color-surface); padding: 2rem; border-radius: var(--radius); width: 100%; max-width: 360px; }
.install-wrap { background: var(--color-surface); padding: 2rem; border-radius: var(--radius); width: 100%; max-width: 480px; margin: 2rem auto; }
.login-wrap h1, .install-wrap h1 { margin-bottom: 1.25rem; }

/* Kanban board */
.page-kanban { max-width: none; }
.kanban-board {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
}
.kanban-column {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    flex: 0 0 280px;
    width: 280px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
}
.kanban-column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.8rem;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--color-border);
    border-radius: var(--radius) var(--radius) 0 0;
}
.kanban-column-count {
    background: rgba(0,0,0,0.08);
    border-radius: 999px;
    padding: 0.05rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
}
.kanban-column-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.6rem;
    min-height: 60px;
}
.kanban-add-btn {
    background: none;
    border: none;
    border-top: 1px solid var(--color-border);
    color: var(--color-muted);
    padding: 0.6rem 0.8rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.85rem;
}
.kanban-add-btn:hover { color: var(--color-text); background: #f5f6f8; }

.kanban-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.6rem 0.7rem;
    margin-bottom: 0.6rem;
    cursor: grab;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.kanban-card:last-child { margin-bottom: 0; }
.kanban-card-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.35rem; word-break: break-word; }
.kanban-card-type, .kanban-card-tags { margin-bottom: 0.35rem; }
.kanban-card-actions { display: flex; gap: 0.4rem; margin-top: 0.4rem; }
.kanban-card-actions .btn-icon { padding: 0.15rem 0.4rem; font-size: 0.78rem; border: 1px solid var(--color-border); border-radius: 4px; }

.sortable-ghost { opacity: 0.4; }
.sortable-chosen { cursor: grabbing; }
.sortable-drag { box-shadow: 0 4px 10px rgba(0,0,0,0.15); }

/* Comments drawer */
.drawer-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 199;
}
.drawer-overlay[hidden] { display: none; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 380px; max-width: 100vw;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    z-index: 200;
    display: flex; flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.2s ease-out;
}
.drawer.open { transform: translateX(0); }
.drawer[hidden] { display: none; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem; border-bottom: 1px solid var(--color-border); }
.drawer-header h2 { margin: 0; font-size: 1.05rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1rem; }
.drawer-footer { display: flex; gap: 0.5rem; padding: 1rem; border-top: 1px solid var(--color-border); }
.drawer-footer input { flex: 1; padding: 0.5rem 0.6rem; border: 1px solid var(--color-border); border-radius: var(--radius); }

/* ----- Responsive ----- */
@media (max-width: 720px) {
    .nav-toggle { display: block; }
    .topnav-bar { padding: 0.75rem 1rem; }
    .topnav-collapse {
        display: none;
        flex-direction: column;
        align-items: stretch;
        padding: 0 1rem 1rem;
        gap: 0.75rem;
    }
    .topnav-collapse.open { display: flex; }
    .topnav-links { flex-direction: column; gap: 0.6rem; }
    .topnav-user { justify-content: space-between; }

    .page { padding: 1rem; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn { width: 100%; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar input, .toolbar select { width: 100%; }

    .modal { padding: 1rem; }
    .modal-box { padding: 1.25rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
    .form-row { flex-direction: column; gap: 0; }

    .kanban-column { flex: 0 0 82vw; width: 82vw; max-height: calc(100vh - 260px); }

    .drawer { width: 100vw; }
}
