@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --color-bg: #f4f5fa;
    --color-surface: #ffffff;
    --color-border: #ececf3;
    --color-text: #1e1e2d;
    --color-muted: #a0a0b2;
    --color-primary: #6c5dd3;
    --color-primary-soft: #efeafb;
    --color-pink: #f0417e;
    --color-red: #ef4b4b;
    --color-teal: #17c3c3;
    --color-orange: #ffa53e;
    --color-error: #ef4b4b;
    --color-success: #17a672;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-soft: 0 4px 24px rgba(17, 17, 38, 0.06);
    --shadow-float: 0 10px 30px rgba(108, 93, 211, 0.35);
    --sidebar-width: 240px;
    --topbar-height: 72px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

h1, h2, h3 {
    font-weight: 700;
}

/* ---------- Auth pages (no sidebar) ---------- */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-box {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 2rem;
    width: 320px;
}

.auth-box h1 {
    margin-top: 0;
    font-size: 1.25rem;
}

.auth-box form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.auth-box label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--color-muted);
}

input {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}

button {
    cursor: pointer;
    font-family: inherit;
}

.auth-box > form > button[type="submit"],
.company-list button {
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.65rem;
    font-size: 1rem;
    font-weight: 600;
}

.link-button {
    background: none;
    border: none;
    color: var(--color-muted);
    text-decoration: underline;
    padding: 0;
    font-size: 0.875rem;
}

.company-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.company-list button {
    width: 100%;
}

.error {
    color: var(--color-error);
    font-size: 0.875rem;
}

.success {
    color: var(--color-success);
    font-size: 0.875rem;
}

.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--color-success);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(23, 166, 114, 0.3);
    font-size: 0.9375rem;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 1000;
}

.toast-visible {
    opacity: 1;
    transform: translateY(0);
}

.inline-form-compact {
    display: inline-block;
    margin-right: 0.75rem;
}

/* ---------- Sidebar ---------- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 1.5rem 1rem;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0 0.5rem;
    min-height: 40px;
}

.sidebar-logo {
    max-width: 150px;
    max-height: 40px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.sidebar-logo-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.sidebar-company-name {
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    color: #6e6e82;
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
}

.sidebar-nav-item:hover {
    background: var(--color-bg);
}

.sidebar-nav-item--active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-weight: 600;
}

.sidebar-nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
}

.sidebar-nav-icon svg {
    width: 100%;
    height: 100%;
}

/* ---------- Topbar ---------- */

.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 90;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-icon-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-surface);
    border: none;
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
}

.topbar-icon-button svg {
    width: 18px;
    height: 18px;
}

.active-company-badge {
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
    border-radius: 999px;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    color: var(--color-muted);
}

.active-company-badge strong {
    color: var(--color-text);
}

.fab-settings {
    position: fixed;
    bottom: 1.75rem;
    right: 1.75rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-float);
    z-index: 150;
}

.fab-settings svg {
    width: 24px;
    height: 24px;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge--draft {
    background: var(--color-border);
    color: #6e6e82;
}

.badge--open {
    background: rgba(239, 75, 75, 0.12);
    color: #c0392b;
}

.badge--partial {
    background: rgba(255, 165, 62, 0.18);
    color: #9a5b00;
}

.badge--paid {
    background: rgba(23, 166, 114, 0.14);
    color: #0f7a52;
}

/* ---------- Filter tabs ---------- */

.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-tab {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
    color: var(--color-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
}

.filter-tab--active {
    background: var(--color-primary);
    color: #fff;
    box-shadow: none;
}

/* ---------- Content area (offset for fixed sidebar/topbar) ---------- */

main {
    padding: 1.5rem;
    max-width: 960px;
    margin: 0 auto;
}

body:has(.sidebar) {
    padding-left: var(--sidebar-width);
}

.sidebar ~ main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem;
    padding-top: calc(var(--topbar-height) + 1.5rem);
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.button {
    display: inline-block;
    background: var(--color-primary);
    color: #fff;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.55rem 1.1rem;
    font-size: 0.9375rem;
    font-weight: 600;
}

.search-bar {
    margin-bottom: 1rem;
}

.search-bar input {
    width: 100%;
    max-width: 360px;
    border-radius: 999px;
    padding-left: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.75rem 1.1rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9375rem;
}

.data-table th {
    background: transparent;
    color: var(--color-muted);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

.panel {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.5rem;
}

.panel h2 {
    margin-top: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.hint {
    color: var(--color-muted);
    font-size: 0.8125rem;
    margin-top: -0.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.form-grid label,
.inline-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.add-form {
    margin-top: 1rem;
}

.add-form summary {
    cursor: pointer;
    color: var(--color-primary);
    font-size: 0.9375rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.inline-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.note-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.note-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-border);
}

.note-date {
    color: var(--color-muted);
    font-size: 0.8125rem;
    min-width: 6rem;
}

.note-description {
    flex: 1;
}

.button-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.button-secondary {
    background: var(--color-surface);
    color: var(--color-primary);
    border: 1.5px solid var(--color-primary);
    border-radius: var(--radius-md);
    padding: 0.5rem 1.1rem;
    font-size: 0.9375rem;
    font-weight: 600;
}

.item-table input,
.item-table select {
    width: 100%;
    font-size: 0.875rem;
}

.item-table td {
    vertical-align: middle;
}

.totals-preview {
    text-align: right;
    margin: 0.75rem 0 1.5rem;
    line-height: 1.6;
}

.form-actions {
    margin-top: 1.5rem;
}

textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
}

select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
}

.form-section {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin: 1rem 0;
}

.form-section legend {
    padding: 0 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.checkbox-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    color: var(--color-text);
}

.settings-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.settings-list li {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 1.1rem 1.4rem;
}

.settings-list a {
    display: block;
    margin-bottom: 20px;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

code {
    background: var(--color-bg);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.875em;
}

/* ---------- Dashboard stat tiles ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stat-tile {
    display: flex;
    align-items: center;
    gap: 1rem;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    color: #fff;
    text-decoration: none;
    box-shadow: var(--shadow-soft);
}

.stat-tile--purple { background: var(--color-primary); }
.stat-tile--pink { background: var(--color-pink); }
.stat-tile--red { background: var(--color-red); }
.stat-tile--teal { background: var(--color-teal); }

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 22px;
    height: 22px;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    display: block;
    font-size: 0.875rem;
    opacity: 0.9;
    margin-top: 0.15rem;
}
