:root {
    --accent-dark: #9a6c29;
    --accent-darker: #7a561f;
    --accent-light: #fbf0e4;
    --main-dark: #2a2a2a;
    --main-mid: #3b3b3b;
    --main-light: #f1f1f1;
    --border-soft: rgba(0, 0, 0, 0.075);
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --card-shadow-hover: 0 6px 18px rgba(0, 0, 0, 0.09);
}

body {
    font-family: 'Source Sans 3', sans-serif;
    background-color: var(--main-light);
    color: var(--main-dark);
}

/* ---------- App shell (sidebar + main) ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
}

.app-content {
    padding: 1.75rem 2rem 4rem;
}

.page-title {
    font-weight: 700;
    margin-bottom: 1.5rem;
}

/* ---------- Sidebar (light) ---------- */
.sidebar {
    width: 250px;
    background: #fff;
    border-right: 1px solid var(--border-soft);
}

@media (min-width: 992px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        flex: 0 0 250px;
    }
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    text-align: center;
    border-bottom: 1px solid var(--border-soft);
}

.sidebar-brand svg {
    width: 120px;
    height: auto;
    max-width: 100%;
}

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0.75rem 0;
    flex: 1 1 auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.4rem;
    color: var(--main-mid);
    text-decoration: none;
    font-weight: 600;
    border-left: 3px solid transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav a i {
    font-size: 1.15rem;
    width: 1.3rem;
    text-align: center;
    color: var(--accent-dark);
}

.sidebar-nav a:hover {
    background: var(--accent-light);
    color: var(--main-dark);
}

.sidebar-nav a.active {
    background: var(--accent-light);
    color: var(--accent-darker);
    border-left-color: var(--accent-dark);
}

.sidebar-footer {
    padding: 1rem 1.4rem;
    border-top: 1px solid var(--border-soft);
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: none;
    border: 0;
    padding: 0;
    font-weight: 600;
    color: var(--main-mid);
}

.sidebar-logout i {
    font-size: 1.15rem;
    color: var(--accent-dark);
}

.sidebar-logout:hover {
    color: var(--main-dark);
}

/* ---------- Mobile top bar ---------- */
.mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.6rem 1rem;
    background: #fff;
    border-bottom: 1px solid var(--border-soft);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.mobile-topbar .topbar-brand {
    font-weight: 700;
    color: var(--accent-dark);
    text-decoration: none;
}

/* ---------- Links & accent ---------- */
a {
    color: var(--accent-dark);
}

a:hover {
    color: var(--accent-darker);
}

/* ---------- Buttons ---------- */
.btn-primary {
    background-color: var(--accent-dark);
    border-color: var(--accent-dark);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--accent-darker);
    border-color: var(--accent-darker);
}

.btn-outline-primary {
    color: var(--accent-dark);
    border-color: var(--accent-dark);
}

.btn-outline-primary:hover {
    background-color: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

/* ---------- Cards ---------- */
.card {
    border: 1px solid var(--border-soft);
    border-radius: 0.6rem;
    box-shadow: var(--card-shadow);
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid var(--border-soft);
    font-weight: 600;
    padding-top: 0.9rem;
    padding-bottom: 0.9rem;
}

/* ---------- Tables ---------- */
.table-dark {
    --bs-table-bg: var(--main-dark);
}

.invoice-table {
    background: #fff;
    border-radius: 0.6rem;
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.invoice-table table {
    margin-bottom: 0;
}

.invoice-table thead th {
    border-top: none;
}

/* Drag-to-reorder column headers */
th[draggable="true"] {
    cursor: grab;
    user-select: none;
}

th[draggable="true"]:active {
    cursor: grabbing;
}

th.col-dragging {
    opacity: 0.4;
}

th.col-drop-target {
    box-shadow: inset 3px 0 0 0 var(--accent-light);
}

/* Click-to-sort headers */
th.sortable {
    cursor: pointer;
}

th.sortable .sort-ind {
    font-size: 0.75em;
    opacity: 0.9;
}

/* ---------- Forms ---------- */
.form-label {
    font-weight: 600;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent-dark);
    box-shadow: 0 0 0 0.2rem rgba(154, 108, 41, 0.2);
}

/* Line-item repeater fixes (carried over) */
#opt-tag {
    display: none;
}

#line-items-container div.form-check {
    display: flex;
    height: 30px;
    align-items: center !important;
    padding-top: 8px;
}

input.form-check-input {
    width: 20px;
    height: 20px;
    margin-right: 10px;
}

input.form-check-input:checked {
    background-color: var(--accent-dark);
    border-color: var(--accent-dark);
}

/* ---------- Stat cards / headline widgets ---------- */
.stat-card {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-top: 3px solid var(--accent-dark);
    border-radius: 0.6rem;
    box-shadow: var(--card-shadow);
    padding: 1.25rem 1.4rem;
    height: 100%;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.stat-card:hover {
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
}

.stat-card .stat-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--main-mid);
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.stat-card .stat-value {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--main-dark);
    line-height: 1.1;
}

.stat-card .stat-sub {
    font-size: 0.85rem;
    color: #6c757d;
    margin-top: 0.3rem;
}

/* Accent variants */
.stat-card.stat-vat { border-top-color: #3b6fa3; }
.stat-card.stat-cis { border-top-color: #b8803d; }
.stat-card.stat-credit { border-top-color: #b54b4b; }
.stat-card.stat-total { border-top-color: var(--accent-dark); }

/* ---------- Auth (guest) pages ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(ellipse at top, rgba(251, 240, 228, 0.6) 0%, var(--main-light) 60%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-logo svg {
    height: 70px;
    width: auto;
}

/* ---------- TaxBot chat widget ---------- */
.taxbot-toggle {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 0;
    background: var(--accent-dark);
    color: #fff;
    font-size: 1.5rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    z-index: 1080;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.taxbot-toggle:hover {
    background: var(--accent-darker);
    transform: translateY(-2px);
}

.taxbot-panel {
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    width: 370px;
    max-width: calc(100vw - 2rem);
    height: 540px;
    max-height: calc(100vh - 8rem);
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow-hover);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1080;
}

.taxbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--accent-dark);
    color: #fff;
}

.taxbot-title {
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.taxbot-close {
    background: none;
    border: 0;
    color: #fff;
    font-size: 1rem;
    opacity: 0.85;
}

.taxbot-close:hover {
    opacity: 1;
}

.taxbot-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: var(--main-light);
}

.taxbot-msg {
    max-width: 85%;
    padding: 0.6rem 0.8rem;
    border-radius: 0.75rem;
    font-size: 0.92rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.taxbot-msg-assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-bottom-left-radius: 0.2rem;
    white-space: normal; /* bot text is rendered HTML; structure comes from tags, not raw newlines */
}

.taxbot-msg-user {
    align-self: flex-end;
    background: var(--accent-light);
    color: var(--main-dark);
    border-bottom-right-radius: 0.2rem;
}

/* Rendered markdown inside the bot's bubbles — keep it compact. */
.taxbot-msg-assistant p {
    margin: 0 0 0.5rem;
}

.taxbot-msg-assistant p:last-child {
    margin-bottom: 0;
}

.taxbot-msg-assistant ul,
.taxbot-msg-assistant ol {
    margin: 0 0 0.5rem;
    padding-left: 1.2rem;
}

.taxbot-msg-assistant li {
    margin-bottom: 0.15rem;
}

.taxbot-msg-assistant code {
    background: var(--main-light);
    padding: 0.05rem 0.3rem;
    border-radius: 0.25rem;
    font-size: 0.85em;
}

.taxbot-msg-assistant hr {
    margin: 0.5rem 0;
    border: 0;
    border-top: 1px solid var(--border-soft);
}

.taxbot-sources {
    align-self: flex-start;
    font-size: 0.72rem;
    color: #6c757d;
    margin-top: -0.3rem;
    padding-left: 0.2rem;
}

.taxbot-typing {
    display: flex;
    gap: 4px;
    align-items: center;
}

.taxbot-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-dark);
    opacity: 0.4;
    animation: taxbot-blink 1.2s infinite both;
}

.taxbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.taxbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes taxbot-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

.taxbot-input {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem 0.2rem;
    border-top: 1px solid var(--border-soft);
}

.taxbot-input textarea {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid #ced4da;
    border-radius: 0.5rem;
    padding: 0.5rem 0.7rem;
    font-size: 0.92rem;
    max-height: 120px;
    overflow-y: auto;
}

.taxbot-input textarea:focus {
    outline: none;
    border-color: var(--accent-dark);
    box-shadow: 0 0 0 0.15rem rgba(154, 108, 41, 0.2);
}

.taxbot-send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    border: 0;
    background: var(--accent-dark);
    color: #fff;
}

.taxbot-send:hover:not(:disabled) {
    background: var(--accent-darker);
}

.taxbot-send:disabled {
    opacity: 0.5;
}

.taxbot-disclaimer {
    margin: 0;
    padding: 0.1rem 0.85rem 0.6rem;
    font-size: 0.68rem;
    color: #9aa0a6;
    text-align: center;
}

/* ---------- Responsive ---------- */
@media screen and (max-width: 999px) {
    /* Shorten table for mobile — target the Subtotal column by name so reordering
       columns doesn't change which one is hidden. */
    .invoice-table tr th[data-col="subtotal"],
    .invoice-table tr td[data-col="subtotal"] {
        display: none;
    }

    .mobile-column,
    .show-header-block {
        flex-direction: column !important;
        margin-bottom: 20px !important;
    }

    .login-form div.d-flex.justify-content-between {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .login-form div.d-flex.justify-content-between > * {
        margin-bottom: 15px;
    }
}
