/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       color: #1a1a1a; background: #f7f8fa; line-height: 1.5; }

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top bar ---- */
.topbar { display: flex; align-items: center; gap: 2rem; padding: 0.75rem 1.5rem;
          background: white; border-bottom: 1px solid #e5e7eb; }
.brand { font-weight: 700; font-size: 1.1rem; }
.brand a { color: #1a1a1a; text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: #4b5563; padding: 0.25rem 0.5rem; border-radius: 4px; }
.topbar nav a:hover { background: #f3f4f6; text-decoration: none; }
.user-menu { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.user-email { color: #6b7280; }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: none; color: #2563eb; cursor: pointer;
               font: inherit; padding: 0; }
.link-button:hover { text-decoration: underline; }

/* ---- Container / layout ---- */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }
.site-footer { text-align: center; padding: 2rem; color: #9ca3af; font-size: 0.85rem; }

/* ---- Auth cards ---- */
.auth-card { max-width: 460px; margin: 3rem auto; background: white;
             padding: 2rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.auth-card h1 { margin-top: 0; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form fieldset { border: 1px solid #e5e7eb; border-radius: 6px; padding: 1rem; }
.auth-form legend { font-weight: 600; padding: 0 0.5rem; }
.auth-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.auth-form input, .auth-form select {
    padding: 0.5rem 0.75rem; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 1rem; /* 16px to prevent iOS zoom on focus */
}
.auth-form input:focus, .auth-form select:focus {
    outline: 2px solid #2563eb; outline-offset: -1px; border-color: transparent;
}
.muted { color: #6b7280; font-size: 0.85rem; }
.error { background: #fee2e2; color: #991b1b; padding: 0.75rem 1rem;
         border-radius: 4px; margin-bottom: 1rem; }

/* ---- Buttons ---- */
button.primary { background: #2563eb; color: white; border: none; padding: 0.6rem 1rem;
                 border-radius: 4px; font-size: 1rem; font-weight: 500; cursor: pointer; }
button.primary:hover { background: #1d4ed8; }

/* ---- Page header ---- */
.page-header { display: flex; align-items: baseline; justify-content: space-between;
               margin-bottom: 1.5rem; }
.page-header h1 { margin: 0; }
.stat-row { display: flex; gap: 1rem; font-size: 0.9rem; }
.stat strong { font-size: 1.05rem; color: #111827; }

/* ---- Data table ---- */
.data-table { width: 100%; border-collapse: collapse; background: white;
              border-radius: 6px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.data-table th, .data-table td { padding: 0.6rem 0.85rem; text-align: left;
                                  border-bottom: 1px solid #f3f4f6; font-size: 0.9rem; }
.data-table th { background: #f9fafb; font-weight: 600; color: #374151;
                 text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

/* ---- Status badges ---- */
.status { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
          font-size: 0.75rem; font-weight: 500; text-transform: capitalize; }
.status-open    { background: #dcfce7; color: #166534; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-closed  { background: #e5e7eb; color: #4b5563; }

/* ---- Empty state ---- */
.empty-state { background: white; padding: 3rem 2rem; text-align: center;
               border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.empty-state h2 { margin-top: 0; }

/* ---- Matter detail ---- */
.matter-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 1rem; margin-bottom: 1rem; }
.matter-meta-card, .matter-actions-card {
    background: white; padding: 1.25rem 1.5rem; border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.matter-meta-card h3, .matter-actions-card h3 { margin-top: 0; font-size: 1rem; }
.motion-form { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.75rem; }
.motion-form select { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid #d1d5db;
                       border-radius: 4px; font-size: 0.95rem; }

.cs-badge { display: inline-block; margin-top: 0.75rem; padding: 0.4rem 0.75rem;
            border-radius: 4px; font-size: 0.85rem; font-weight: 500; }
.cs-badge-on       { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.cs-badge-fallback { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

.draft-result { background: white; padding: 1.5rem 2rem; border-radius: 8px;
                box-shadow: 0 1px 3px rgba(0,0,0,0.04); margin-top: 1rem; }
.draft-result header { border-bottom: 1px solid #e5e7eb; padding-bottom: 0.5rem;
                       margin-bottom: 1rem; }
.draft-result header h2 { margin: 0; }
.draft-body { font-family: Georgia, "Times New Roman", serif; line-height: 1.7;
              font-size: 0.95rem; max-width: 75ch; }
.draft-body p { margin: 0 0 1rem; }

@media (max-width: 768px) {
    .matter-grid { grid-template-columns: 1fr; }
}

/* ---- Today's Briefing ---- */
.briefing-card { background: white; border-radius: 8px; padding: 1.5rem 2rem;
                 box-shadow: 0 1px 3px rgba(0,0,0,0.05); margin-bottom: 1.5rem;
                 line-height: 1.65; }
.briefing-content { font-size: 0.95rem; }
.briefing-content br + br { display: block; margin: 0.4rem 0; content: ""; }
.brief-tier { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 4px;
              color: white; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em;
              margin: 1.25rem 0 0.5rem; }
.brief-red    { background: #b91c1c; }
.brief-yellow { background: #b45309; }
.brief-green  { background: #166534; }

.snapshot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
                 gap: 1rem; margin-top: 1rem; }
.snapshot-card { background: white; padding: 1.25rem; border-radius: 8px;
                 box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.snapshot-card h3 { margin: 0 0 0.75rem; font-size: 0.95rem; color: #1a1a1a;
                    border-bottom: 1px solid #e5e7eb; padding-bottom: 0.5rem; }
.snapshot-list { list-style: none; padding: 0; margin: 0; }
.snapshot-list li { padding: 0.5rem 0; border-bottom: 1px solid #f3f4f6; font-size: 0.9rem; }
.snapshot-list li:last-child { border-bottom: none; }

/* ---- Filter bar ---- */
.filter-bar { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end;
              background: white; padding: 0.75rem 1rem; border-radius: 6px;
              margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.filter-bar label { display: flex; flex-direction: column; gap: 0.25rem;
                    font-size: 0.8rem; color: #6b7280; }
.filter-bar select { padding: 0.4rem 0.6rem; border: 1px solid #d1d5db;
                     border-radius: 4px; font-size: 0.9rem; min-width: 150px; }
.clear-filters { font-size: 0.85rem; align-self: end; padding: 0.4rem 0; }

/* ---- Connections page ---- */
.connection-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
                   gap: 1rem; margin-top: 1.5rem; }
.connection-card { background: white; padding: 1.25rem 1.5rem; border-radius: 8px;
                   box-shadow: 0 1px 3px rgba(0,0,0,0.04); border: 1px solid #e5e7eb; }
.connection-card.connected { border-color: #166534; }
.connection-header { display: flex; align-items: baseline; justify-content: space-between;
                     gap: 1rem; margin-bottom: 0.25rem; }
.connection-header h2 { margin: 0; font-size: 1.1rem; }
.connection-desc { color: #4b5563; font-size: 0.9rem; margin: 0 0 1rem; }
.connection-meta { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 0.75rem;
                   margin: 0 0 1rem; font-size: 0.85rem; }
.connection-meta dt { color: #6b7280; }
.connection-meta dd { margin: 0; color: #1a1a1a; font-variant-numeric: tabular-nums; }
.connection-actions { display: flex; gap: 0.75rem; align-items: center; }
.button-link { display: inline-block; padding: 0.5rem 1rem; border-radius: 4px;
               background: #2563eb; color: white; text-decoration: none; font-size: 0.9rem; }
.button-link:hover { background: #1d4ed8; text-decoration: none; }
.link-button.danger { color: #b91c1c; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: 0.5rem 1rem; }
    .container { padding: 1rem; }
    .data-table { font-size: 0.85rem; }
    .data-table th, .data-table td { padding: 0.5rem 0.5rem; }
}
