@font-face {
    font-family: 'SpaceAge';
    src: url('fonts/space-age.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ----- DB Theme tokens (light + dark), ported from SW-R1 ------------- */

:root {
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --transition: all 0.2s ease;
}

[data-theme="light"] {
    --bg-body: #F5F5F3;
    --bg-card: #ffffff;
    --bg-input: #F5F5F3;
    --bg-input-focus: #ffffff;
    --text-primary: #282D37;
    --text-secondary: #596163;
    --text-muted: #878C96;
    --border-color: #E0DEDA;
    --accent: #EC0016;
    --accent-light: #F4364C;
    --accent-bg: rgba(236, 0, 22, 0.07);
    --green: #408335;
    --green-bg: rgba(64, 131, 53, 0.10);
    --red: #EC0016;
    --red-bg: rgba(236, 0, 22, 0.08);
    --orange: #F39200;
    --orange-bg: rgba(243, 146, 0, 0.10);
    --shadow: 0 2px 6px rgba(40,45,55,0.04);
    --shadow-md: 0 4px 16px rgba(40,45,55,0.07);
    --shadow-lg: 0 10px 25px rgba(40,45,55,0.07);
    --navbar-bg: #ffffff;
    --navbar-shadow: 0 2px 8px rgba(40,45,55,0.06);
    --focus-ring: rgba(236, 0, 22, 0.10);
    --accent-shadow: rgba(236, 0, 22, 0.25);
}

[data-theme="dark"] {
    --bg-body: #1E1E1E;
    --bg-card: #282D37;
    --bg-input: rgba(255,255,255,0.07);
    --bg-input-focus: rgba(255,255,255,0.12);
    --text-primary: #F0EFED;
    --text-secondary: #B4B8C0;
    --text-muted: #878C96;
    --border-color: rgba(255,255,255,0.10);
    --accent: #F4364C;
    --accent-light: #F7606F;
    --accent-bg: rgba(244, 54, 76, 0.15);
    --green: #5DA550;
    --green-bg: rgba(93, 165, 80, 0.15);
    --red: #F4364C;
    --red-bg: rgba(244, 54, 76, 0.12);
    --orange: #F39200;
    --orange-bg: rgba(243, 146, 0, 0.15);
    --shadow: none;
    --shadow-md: 0 4px 20px rgba(0,0,0,0.35);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.45);
    --navbar-bg: #282D37;
    --navbar-shadow: 0 4px 20px rgba(0,0,0,0.35);
    --focus-ring: rgba(244, 54, 76, 0.15);
    --accent-shadow: rgba(244, 54, 76, 0.30);
}

/* ----- Base ---------------------------------------------------------- */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
    transition: background 0.2s, color 0.2s;
}

button { font-family: inherit; }

/* ----- Top bar ------------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--navbar-bg);
    box-shadow: var(--navbar-shadow);
    position: sticky;
    top: 0;
    z-index: 5;
}

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

.brand img {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ----- Buttons (DB style) ------------------------------------------- */

.btn-glass {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-glass:hover {
    background: var(--border-color);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-icon {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
}
.btn-icon:hover {
    background: var(--accent-bg);
    color: var(--accent);
    border-color: transparent;
}

.btn-primary {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}
.btn-primary:hover {
    background: var(--accent-light);
    box-shadow: 0 4px 12px var(--accent-shadow);
    transform: translateY(-1px);
}

/* ----- Layout -------------------------------------------------------- */

main {
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 20px 80px;
    animation: fadeInUp 0.3s ease-out;
}

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

/* ----- New task card ------------------------------------------------ */

.glass-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

.new-task {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.new-task input[type="text"],
.new-task select,
dialog input[type="url"] {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.new-task input[type="text"] {
    flex: 1;
    min-width: 0;
}

.new-task input[type="text"]:focus,
.new-task select:focus,
dialog input[type="url"]:focus {
    background: var(--bg-input-focus);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.new-task input::placeholder { color: var(--text-muted); }

.new-task select { cursor: pointer; }

/* ----- Task groups & lists ------------------------------------------ */

.task-group {
    margin-bottom: 24px;
}

.task-group h2 {
    margin: 0 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 4px;
}

.count {
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.task-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.task {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.task:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.task .check {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    font-size: 14px;
    line-height: 1;
    transition: var(--transition);
    padding: 0;
}

.task .check:hover { border-color: var(--accent); }

.task[data-status="in_progress"] .check {
    border-color: var(--orange);
    background: var(--orange-bg);
}
.task[data-status="in_progress"] .check::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--orange);
}

.task[data-status="done"] .check {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}
.task[data-status="done"] .check::after {
    content: "✓";
    font-weight: 700;
    font-size: 13px;
}

.task[data-status="done"] .task-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-body {
    flex: 1;
    min-width: 0;
}

.task-title {
    font-size: 14.5px;
    font-weight: 500;
    color: var(--text-primary);
    word-wrap: break-word;
    line-height: 1.3;
}

.task-meta {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.priority {
    font-size: 10.5px;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.task[data-priority="high"] .priority {
    background: var(--red-bg);
    color: var(--red);
}
.task[data-priority="medium"] .priority {
    background: var(--orange-bg);
    color: var(--orange);
}
.task[data-priority="low"] .priority {
    background: var(--accent-bg);
    color: var(--accent);
}

.task-actions {
    display: flex;
    gap: 4px;
    opacity: 0.55;
    transition: var(--transition);
}

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

.task-actions button {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    width: 30px;
    height: 30px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.task-actions button:hover {
    background: var(--bg-body);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.task-actions .delete:hover {
    background: var(--red-bg);
    color: var(--red);
    border-color: transparent;
}

/* ----- Empty / errors ----------------------------------------------- */

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

.error {
    background: var(--red-bg);
    border: 1px solid var(--red);
    color: var(--red);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin: 14px 0;
    font-size: 13px;
    font-weight: 500;
}

.hidden { display: none !important; }

/* ----- Settings dialog ---------------------------------------------- */

dialog {
    background: var(--bg-card);
    color: var(--text-primary);
    border: none;
    border-radius: var(--radius);
    padding: 24px;
    max-width: 440px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

dialog::backdrop {
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
}

dialog h3 {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 700;
}

dialog label {
    display: block;
    font-size: 12.5px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 6px;
}

dialog input[type="url"] {
    width: 100%;
    margin-top: 4px;
}

dialog .hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 10px;
    line-height: 1.5;
}

dialog code {
    background: var(--bg-body);
    color: var(--text-primary);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11.5px;
    border: 1px solid var(--border-color);
}

dialog menu {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0;
    margin: 20px 0 0;
}

/* ----- IOTECK Loader (ported from SW-R1) ---------------------------- */

#loader-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.4s ease;
}

#loader-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.ioteck-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
}

.ioteck-loader-svg-wrap {
    position: relative;
}

.ioteck-loader svg {
    width: 13rem;
    height: 3.25rem;
    position: relative;
    z-index: 1;
}

.ioteck-loader .glow {
    position: absolute;
    inset: 0;
    filter: blur(18px);
    background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--accent));
    opacity: 0.25;
    animation: ioteck-pulse 2s ease-in-out infinite;
    border-radius: 50%;
}

@keyframes ioteck-pulse {
    0%, 100% { opacity: 0.18; transform: scale(1); }
    50%      { opacity: 0.40; transform: scale(1.10); }
}

@keyframes ioteck-draw-loop {
    0%   { stroke-dashoffset: 500; }
    40%  { stroke-dashoffset: 0; }
    60%  { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -500; }
}

@keyframes ioteck-fill-loop {
    0%, 35%  { opacity: 0; }
    45%, 55% { opacity: 1; }
    65%, 100% { opacity: 0; }
}

.ioteck-loader .stroke-text {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    animation: ioteck-draw-loop 3.5s ease-in-out infinite;
}

.ioteck-loader .fill-text {
    opacity: 0;
    animation: ioteck-fill-loop 3.5s ease-in-out infinite;
}

.ioteck-loader .grad-start { stop-color: var(--accent); }
.ioteck-loader .grad-end   { stop-color: var(--accent-light); }

.ioteck-dots { display: flex; gap: 6px; }

.ioteck-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    animation: ioteck-bounce 0.6s ease-in-out infinite;
}
.ioteck-dot:nth-child(2) { animation-delay: 0.15s; }
.ioteck-dot:nth-child(3) { animation-delay: 0.30s; }

@keyframes ioteck-bounce {
    0%, 100% { transform: translateY(0); opacity: 0.45; }
    50%      { transform: translateY(-9px); opacity: 1; }
}

.ioteck-loader-status {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    margin: 0;
}

/* Inline mini loader for refreshes */
.mini-loader {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    margin-left: 6px;
}
.mini-loader .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: ioteck-bounce 0.6s ease-in-out infinite;
}
.mini-loader .dot:nth-child(2) { animation-delay: 0.12s; }
.mini-loader .dot:nth-child(3) { animation-delay: 0.24s; }

/* ----- Compact mode (Linux tray popup) ------------------------------ */

body[data-mode="compact"] main {
    padding: 12px 14px 16px;
}

body[data-mode="compact"] .topbar {
    padding: 10px 14px;
}

body[data-mode="compact"] .brand h1 { font-size: 15px; }
body[data-mode="compact"] .brand img { width: 22px; height: 22px; }

body[data-mode="compact"] .glass-card { padding: 12px; margin-bottom: 14px; }
body[data-mode="compact"] .task-group  { margin-bottom: 14px; }
body[data-mode="compact"] .task        { padding: 10px 12px; }
body[data-mode="compact"] .task-title  { font-size: 13.5px; }

/* ----- Mobile tweaks ------------------------------------------------- */

@media (max-width: 480px) {
    main { padding: 16px 14px 80px; }
    .topbar { padding: 12px 14px; }
    .new-task { flex-wrap: wrap; }
    .new-task input[type="text"] { flex-basis: 100%; }
    .glass-card { padding: 14px; }
}
