:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --focus: #1d4ed8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --s-open: #2563eb;
  --s-progress: #d97706;
  --s-blocked: #dc2626;
  --s-completed: #059669;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--primary); color: #fff; padding: .5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Header */
.app-header {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 700;
}
.app-header h1 { font-size: 1.15rem; margin: 0; }
.app-nav { display: flex; gap: .25rem; margin-left: .5rem; }
.nav-link {
  padding: .4rem .7rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #e0ecff; color: var(--primary-dark); }
.user-box { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.user-email { color: var(--muted); font-size: .9rem; }

/* Layout */
.app-main { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem;
}
.auth-card { max-width: 420px; margin: 3rem auto; text-align: center; }
.embed-login { margin-top: 1rem; }
.muted { color: var(--muted); }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.toolbar h2 { margin: 0; font-size: 1.4rem; }
.toolbar .spacer { flex: 1; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px;
  padding: .5rem .9rem; border: 1px solid transparent; background: var(--bg); color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Forms */
.field { margin-bottom: .9rem; display: flex; flex-direction: column; gap: .3rem; }
.field label { font-weight: 600; font-size: .9rem; }
.field input, .field select, .field textarea {
  font: inherit; padding: .55rem .65rem; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
.field textarea { min-height: 90px; resize: vertical; }
.field .hint { color: var(--muted); font-size: .8rem; }
.field .error-text { color: var(--danger); font-size: .82rem; }
.field-invalid input, .field-invalid select, .field-invalid textarea { border-color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

/* Filters */
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }
.filters .field { margin: 0; min-width: 150px; }

/* Cards / lists */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.item-card { display: flex; flex-direction: column; gap: .5rem; }
.item-card h3 { margin: 0; font-size: 1.05rem; }
.item-card .row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.item-card .desc { color: var(--muted); font-size: .9rem; }
.card-actions { display: flex; gap: .4rem; margin-top: auto; }

/* Task table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.tasks { width: 100%; border-collapse: collapse; min-width: 720px; }
table.tasks th, table.tasks td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
table.tasks th { background: #f8fafc; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.tasks tbody tr { cursor: pointer; }
table.tasks tbody tr:hover { background: #f8fafc; }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-status { color: #fff; }
.status-Open { background: var(--s-open); }
.status-InProgress { background: var(--s-progress); }
.status-Blocked { background: var(--s-blocked); }
.status-Completed { background: var(--s-completed); }
.badge-priority { border: 1px solid var(--border); background: #fff; color: var(--text); }
.prio-Urgent { border-color: var(--danger); color: var(--danger-dark); }
.prio-High { border-color: #d97706; color: #b45309; }

/* States */
.state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.state h3 { color: var(--text); margin: .25rem 0; }
.spinner {
  width: 34px; height: 34px; border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; margin: 0 auto 1rem; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state-error { border: 1px solid #fecaca; background: #fef2f2; color: var(--danger-dark); border-radius: var(--radius); }

/* Detail */
.detail-head { display: flex; gap: .75rem; align-items: flex-start; flex-wrap: wrap; }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; margin: 1rem 0; }
.meta-item .k { font-size: .78rem; color: var(--muted); text-transform: uppercase; }
.meta-item .v { font-weight: 600; }
.comment { border-top: 1px solid var(--border); padding: .75rem 0; }
.comment .who { font-weight: 600; font-size: .9rem; }
.comment .when { color: var(--muted); font-size: .8rem; }

/* Toast */
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; box-shadow: var(--shadow); z-index: 50;
}
.toast.error { background: var(--danger-dark); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 1rem;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; max-width: 480px; width: 100%; box-shadow: var(--shadow); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.modal-wide { max-width: 640px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .app-header h1 { font-size: 1rem; }
  .user-email { display: none; }
}

[hidden]{display:none!important;}
