/* GetMyPermit CRM - Design System v2 */

:root {
    /* Typography scale */
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-base: 13px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 20px;
    --fs-2xl: 24px;
    --fs-3xl: 32px;
    --fs-hero: 44px;

    /* Spacing scale */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
    --sp-12: 48px;

    /* Radius */
    --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-xl: 12px; --r-2xl: 16px;

    /* Dark palette */
    --bg: #0a0a0a;
    --bg-elevated: #111113;
    --bg-subtle: #161618;
    --bg-subtlest: #1c1c1f;
    --bg-hover: rgba(255,255,255,0.03);
    --bg-active: rgba(255,255,255,0.05);

    /* Borders */
    --border: rgba(255,255,255,0.06);
    --border-hover: rgba(255,255,255,0.10);
    --border-strong: rgba(255,255,255,0.14);
    --border-accent: rgba(99,102,241,0.4);

    /* Text */
    --text: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --text-muted: #52525b;
    --text-disabled: #3f3f46;

    /* Accent - indigo (mniej krzykliwe niż blue) */
    --accent: #6366f1;
    --accent-hover: #5856eb;
    --accent-subtle: rgba(99,102,241,0.10);
    --accent-border: rgba(99,102,241,0.25);

    /* Semantic */
    --success: #10b981;
    --success-subtle: rgba(16,185,129,0.1);
    --warn: #f59e0b;
    --warn-subtle: rgba(245,158,11,0.1);
    --danger: #ef4444;
    --danger-subtle: rgba(239,68,68,0.1);
    --info: #06b6d4;
    --info-subtle: rgba(6,182,212,0.1);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.4);
    --shadow-focus: 0 0 0 3px rgba(99,102,241,0.15);
}

[data-theme="light"] {
    --bg: #fafafa;
    --bg-elevated: #ffffff;
    --bg-subtle: #f4f4f5;
    --bg-subtlest: #e4e4e7;
    --bg-hover: rgba(0,0,0,0.03);
    --bg-active: rgba(0,0,0,0.05);
    --border: rgba(0,0,0,0.07);
    --border-hover: rgba(0,0,0,0.12);
    --border-strong: rgba(0,0,0,0.18);
    --text: #18181b;
    --text-secondary: #52525b;
    --text-tertiary: #71717a;
    --text-muted: #a1a1aa;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.12);
}

/* === GLOBAL === */
* { box-sizing: border-box; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-feature-settings: 'cv11', 'ss01', 'ss03';
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); }

::selection { background: var(--accent); color: white; }

/* === ANIMATIONS === */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shimmer { 0% { background-position: -1000px 0; } 100% { background-position: 1000px 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.animate-enter { animation: fadeIn 200ms ease-out forwards; }
.animate-spin { animation: spin 700ms linear infinite; }

/* === TYPOGRAPHY === */
.heading-1 { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -0.02em; color: var(--text); }
.heading-2 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.heading-3 { font-size: var(--fs-lg); font-weight: 600; color: var(--text); }
.text-body { font-size: var(--fs-md); color: var(--text); }
.text-sm { font-size: var(--fs-sm); color: var(--text-secondary); }
.text-xs { font-size: var(--fs-xs); color: var(--text-tertiary); letter-spacing: 0.02em; }
.mono { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* === INPUTS === */
.input, .filter-input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--r-md);
    padding: 8px 12px;
    font-size: var(--fs-md);
    font-family: inherit;
    transition: border-color 150ms, background 150ms, box-shadow 150ms;
    width: 100%;
}
.input:hover, .filter-input:hover { border-color: var(--border-hover); }
.input:focus, .filter-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
    background: var(--bg-elevated);
}
.input[readonly], .input[disabled] { background: var(--bg-subtle); color: var(--text-muted); cursor: not-allowed; }

select.input, select.filter-input {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'><path d='M3 5L6 8L9 5' stroke='%23a1a1aa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat; background-position: right 8px center;
    padding-right: 28px; appearance: none;
}

label {
    display: block;
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    font-size: var(--fs-base);
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms, border-color 120ms, color 120ms;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border-hover); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

.btn-danger { background: var(--danger-subtle); border-color: rgba(239,68,68,0.25); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.15); }

.btn-success { background: var(--success-subtle); border-color: rgba(16,185,129,0.25); color: #6ee7b7; }
.btn-success:hover:not(:disabled) { background: rgba(16,185,129,0.15); }

.btn-sm { padding: 5px 10px; font-size: var(--fs-sm); }
.btn-xs { padding: 3px 8px; font-size: var(--fs-xs); gap: 4px; }
.btn-icon { padding: 7px; width: 32px; height: 32px; }

/* === CARD === */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    transition: border-color 150ms;
    overflow: hidden;
}
.card:hover { border-color: var(--border-hover); }

.card-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--fs-md);
    font-weight: 600;
}
.card-body { padding: 16px; }
.card-compact { padding: 12px 14px; }
.card-padded { padding: 20px; }

/* === SIDEBAR === */
.sidebar-link {
    transition: background 100ms, color 100ms;
    position: relative;
}
.sidebar-link:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-link.active {
    background: var(--accent-subtle);
    color: var(--text);
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10%;
    bottom: 10%;
    width: 2px;
    background: var(--accent);
    border-radius: 1px;
}

/* === SIDEBAR SUBMENU === */
.sidebar-sub {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 4px 0 4px 32px;
    position: relative;
}
.sidebar-sub::before {
    content: '';
    position: absolute;
    left: 22px; top: 2px; bottom: 2px;
    width: 1px;
    background: var(--border);
}
.sidebar-sublink {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 12px;
    border-radius: var(--r-sm);
    font-size: 12px;
    color: var(--text-tertiary);
    text-decoration: none;
    transition: color 100ms, background 100ms;
    position: relative;
}
.sidebar-sublink .dot {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    transition: background 100ms;
}
.sidebar-sublink:hover { color: var(--text); }
.sidebar-sublink:hover .dot { background: var(--text-secondary); }
.sidebar-sublink.active { color: var(--text); background: var(--bg-hover); }
.sidebar-sublink.active .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }

/* === SIDEBAR FOOTER === */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidebar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    width: 100%;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text-tertiary);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background 100ms, border-color 100ms, color 100ms;
    text-align: left;
}
.sidebar-search:hover {
    background: var(--bg-subtlest);
    border-color: var(--border-hover);
    color: var(--text-secondary);
}
.sidebar-search > i { font-size: 14px; flex-shrink: 0; }
.sidebar-search > span { flex: 1; }
.sidebar-kbd {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    padding: 1px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-muted);
    letter-spacing: 0.02em;
    flex-shrink: 0;
    line-height: 1.4;
}
.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: var(--r-md);
    background: transparent;
    transition: background 100ms;
}
.sidebar-user-card:hover { background: var(--bg-hover); }
.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}
.sidebar-user-name {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.4;
    margin-top: 1px;
}
.sidebar-user-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.sidebar-icon-btn {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 14px;
    cursor: pointer;
    transition: background 100ms, color 100ms;
}
.sidebar-icon-btn:hover { background: var(--bg-subtle); color: var(--text); }
#sidebar-logout:hover { color: var(--danger); }

/* === SAVED VIEWS === */
.sv-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    flex-wrap: wrap;
}
.sv-label {
    font-size: 11px; color: var(--text-tertiary);
    display: inline-flex; align-items: center; gap: 4px;
}
.sv-chips { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.sv-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 100ms;
    white-space: nowrap;
}
.sv-chip:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-hover); }
.sv-chip.active {
    background: var(--accent-subtle);
    border-color: var(--accent-border);
    color: var(--accent);
    font-weight: 500;
}
.sv-add {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; font-size: 11px;
    background: transparent;
    border: 1px dashed var(--border-hover);
    border-radius: 999px;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 100ms;
    margin-left: auto;
}
.sv-add:hover { color: var(--accent); border-color: var(--accent); border-style: solid; }

/* === TEMPLATE PICKER === */
.tpl-picker {
    position: absolute;
    z-index: 100;
    min-width: 360px;
    max-width: 440px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tpl-search {
    width: 100%;
    padding: 7px 10px;
    font-size: var(--fs-sm);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    outline: none;
}
.tpl-search:focus { border-color: var(--accent-border); }
.tpl-options {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 0;
}
.tpl-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background 100ms;
}
.tpl-option:hover { background: var(--bg-hover); }
.tpl-ic {
    width: 28px; height: 28px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-subtle);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
}
.tpl-body { flex: 1; min-width: 0; }
.tpl-name { font-size: var(--fs-sm); color: var(--text); font-weight: 500; line-height: 1.3; }
.tpl-desc { font-size: 10px; color: var(--text-tertiary); line-height: 1.3; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-cat {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--bg-subtle);
    color: var(--text-tertiary);
    flex-shrink: 0;
    font-weight: 500;
}
.tpl-empty { padding: 16px; text-align: center; color: var(--text-tertiary); font-size: var(--fs-xs); }
.tpl-footer { padding: 6px 8px 2px; border-top: 1px solid var(--border); }

/* === INLINE EDIT === */
.inline-editable { position: relative; transition: background 100ms; }
.inline-editable:hover {
    background: var(--bg-hover);
    outline: 1px dashed var(--border-hover);
    outline-offset: -2px;
    border-radius: var(--r-sm);
}
.inline-editable:hover::after {
    content: '✎';
    position: absolute;
    top: 50%; right: 4px;
    transform: translateY(-50%);
    font-size: 10px;
    color: var(--text-disabled);
    pointer-events: none;
}
.inline-edit-wrap { display: flex; align-items: center; gap: 4px; }
.inline-edit-select {
    flex: 1;
    padding: 3px 6px;
    font-size: var(--fs-xs);
    background: var(--bg-elevated);
    border: 1px solid var(--accent-border);
    border-radius: var(--r-sm);
    color: var(--text);
    outline: none;
    min-width: 100px;
}
.inline-edit-cancel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px; height: 20px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--r-sm);
    font-size: 10px;
}
.inline-edit-cancel:hover { background: var(--bg-subtle); color: var(--text); }
.inline-edit-loading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

/* === TAGS === */
.tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    color: var(--tag-color, var(--text-secondary));
    background: color-mix(in oklab, var(--tag-color) 12%, transparent);
    border: 1px solid color-mix(in oklab, var(--tag-color) 25%, transparent);
    white-space: nowrap;
    line-height: 1.5;
    max-width: 100%;
}
.tag-chip-sm {
    font-size: 10px;
    padding: 2px 7px 2px 6px;
    gap: 4px;
}
.tag-chip .tag-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--tag-color, var(--accent));
    flex-shrink: 0;
}
.tag-chip .tag-rm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px; height: 14px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: currentColor;
    opacity: 0.6;
    cursor: pointer;
    font-size: 10px;
    padding: 0;
    margin-left: 2px;
    transition: opacity 100ms, background 100ms;
}
.tag-chip .tag-rm:hover {
    opacity: 1;
    background: color-mix(in oklab, var(--tag-color) 25%, transparent);
}
.tag-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px dashed var(--border-hover);
    cursor: pointer;
    transition: all 100ms;
}
.tag-add-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    border-style: solid;
}
.tag-add-btn i { font-size: 10px; }

/* Standalone dot (for list view / kanban cards) */
.tag-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}
.tag-dots .tag-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* === TAG PICKER DROPDOWN === */
.tag-picker {
    position: absolute;
    z-index: 100;
    min-width: 260px;
    max-width: 340px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tag-search {
    width: 100%;
    padding: 6px 10px;
    font-size: var(--fs-sm);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    outline: none;
}
.tag-search:focus { border-color: var(--accent-border); }
.tag-options {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 0;
}
.tag-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background 100ms;
}
.tag-option:hover { background: var(--bg-hover); }
.tag-opt-desc {
    font-size: 10px;
    color: var(--text-tertiary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tag-option-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: var(--fs-xs);
}

.tag-create {
    border-top: 1px solid var(--border);
    padding: 8px 4px 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.tag-create-label { font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; }
.tag-create-preview { display: flex; align-items: center; }
.tag-create-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag-colors { display: flex; gap: 4px; }
.tag-color {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: border-color 100ms, transform 100ms;
}
.tag-color:hover { transform: scale(1.1); }
.tag-color.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-elevated); }

/* === TABLE === */
.gmp-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.gmp-table thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    background: var(--bg-elevated);
    z-index: 1;
    user-select: none;
}
.gmp-table thead th[data-sort] { cursor: pointer; transition: color 100ms; }
.gmp-table thead th[data-sort]:hover { color: var(--text); }
.gmp-table thead th[data-sort]::after {
    content: '↕'; opacity: 0.3; margin-left: 4px; font-size: 10px;
}
.gmp-table thead th.sort-asc::after { content: '↑'; opacity: 1; color: var(--accent); }
.gmp-table thead th.sort-desc::after { content: '↓'; opacity: 1; color: var(--accent); }

.gmp-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 100ms;
}
.gmp-table tbody tr:hover { background: var(--bg-hover); }
.gmp-table tbody tr.clickable { cursor: pointer; }
.gmp-table tbody td { padding: 12px 14px; vertical-align: middle; }

/* === ROW OPEN AFFORDANCE ===
   Wiersze clickable: akcent z lewej strony na hover + cursor pointer.
   .row-open td/th są ukryte (legacy - pozostały w HTML, ale nie renderują się).
   Zero zmian layoutu, brak przesuwania kolumn. */
.gmp-table .row-open { display: none; }
.row-open-btn { display: none; }

.gmp-table tbody tr.clickable td:first-child {
    box-shadow: inset 2px 0 0 transparent;
    transition: box-shadow 100ms;
}
.gmp-table tbody tr.clickable:hover td:first-child {
    box-shadow: inset 2px 0 0 var(--accent);
}

/* === BADGES (unified) === */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
    line-height: 1.6;
}
.badge-neutral  { background: var(--bg-subtle); color: var(--text-secondary); }
.badge-lead       { background: rgba(161,161,170,0.12); color: #d4d4d8; }
.badge-zlecona    { background: var(--accent-subtle); color: #a5b4fc; }
.badge-aktywna    { background: var(--success-subtle); color: #6ee7b7; }
.badge-zakonczona { background: var(--bg-subtle); color: var(--text-secondary); }
.badge-archiwum   { background: rgba(75,85,99,0.2); color: var(--text-muted); }
.badge-stage      { background: rgba(168,85,247,0.12); color: #d8b4fe; }
.badge-category   { background: rgba(236,72,153,0.08); color: #fbcfe8; }
.badge-inactive-14 { background: var(--warn-subtle); color: #fcd34d; }
.badge-inactive-30 { background: var(--danger-subtle); color: #fca5a5; }
.badge-success { background: var(--success-subtle); color: #6ee7b7; }
.badge-warn { background: var(--warn-subtle); color: #fcd34d; }
.badge-danger { background: var(--danger-subtle); color: #fca5a5; }
.badge-info { background: var(--info-subtle); color: #67e8f9; }

/* Dot indicator */
.badge-dot::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.8;
}

/* === MODALS === */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: fadeIn 150ms ease-out;
}
.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: fadeIn 200ms ease-out;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* === LOADING === */
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

/* Skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--bg-subtle) 0%, var(--bg-subtlest) 50%, var(--bg-subtle) 100%);
    background-size: 1000px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--r-sm);
}

/* === TABS (underlined) === */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--sp-6);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: var(--fs-base);
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: color 120ms, border-color 120ms;
    font-family: inherit;
    margin-bottom: -1px;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-count {
    display: inline-flex;
    padding: 1px 6px;
    background: var(--bg-subtle);
    border-radius: 999px;
    font-size: 10px;
    color: var(--text-tertiary);
    font-weight: 600;
    min-width: 18px;
    justify-content: center;
}
.tab.active .tab-count { background: var(--accent-subtle); color: #a5b4fc; }

/* === AVATAR === */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--avatar-color, var(--accent)), var(--avatar-color2, #a855f7));
    letter-spacing: 0;
}
.avatar-sm { width: 22px; height: 22px; font-size: 9px; }
.avatar-lg { width: 40px; height: 40px; font-size: 13px; }

/* === PAGINATION === */
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.pagination button {
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    border-radius: var(--r-md);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: all 100ms;
    font-family: inherit;
}
.pagination button:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); border-color: var(--border-hover); }
.pagination button.active { background: var(--accent); color: white; border-color: var(--accent); }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* === EMPTY STATE === */
.empty-state {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 40px;
    color: var(--text-disabled);
    margin-bottom: 12px;
    display: block;
}
.empty-state-title { color: var(--text-secondary); font-weight: 500; margin-bottom: 4px; font-size: var(--fs-md); }

/* === PAGE LAYOUT === */
.app-layout { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; padding: 24px 32px; max-width: 1400px; }

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.page-title {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.page-subtitle {
    color: var(--text-tertiary);
    font-size: var(--fs-sm);
    margin-top: 4px;
}

/* === DIVIDER === */
.divider { border-top: 1px solid var(--border); margin: 16px 0; }

/* === TEXT HELPERS === */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-success { color: var(--success); }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }

/* === MOBILE TOPBAR (pod 900px) === */
.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 30;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    min-height: 52px;
}
.mobile-hamburger {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--r-md);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}
.mobile-hamburger:active { background: var(--bg-hover); }
.mobile-topbar-brand {
    display: flex; align-items: center; gap: 8px;
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
}
.mobile-topbar-brand .ico {
    width: 26px; height: 26px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    color: white;
    flex-shrink: 0;
}

/* Mobile drawer overlay */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 40;
    backdrop-filter: blur(2px);
}
.sidebar-backdrop.open { display: block; }

/* === MOBILE <= 900px === */
@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .mobile-topbar { display: flex; }

    aside#main-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh !important;
        width: 280px !important;
        transform: translateX(-100%);
        transition: transform 200ms ease;
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }
    aside#main-sidebar.open { transform: translateX(0); }

    .app-main {
        padding: 16px;
        max-width: 100%;
    }
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }
    .page-header .flex { flex-wrap: wrap; }
    .page-title { font-size: var(--fs-xl); }
}

/* === SMALL MOBILE <= 600px === */
@media (max-width: 600px) {
    :root {
        --fs-2xl: 20px;
        --fs-xl: 18px;
        --fs-hero: 28px;
        --fs-3xl: 24px;
    }

    /* Touch-friendly minimums */
    .btn, .btn-sm {
        min-height: 36px;
    }
    .btn-primary, .btn-secondary {
        min-height: 40px;
    }

    /* Modal full-screen on mobile */
    .modal-backdrop {
        padding: 0 !important;
        align-items: flex-end;
    }
    .modal-content {
        max-width: 100% !important;
        width: 100% !important;
        max-height: 95vh !important;
        border-radius: var(--r-xl) var(--r-xl) 0 0 !important;
        animation: slideUp 240ms ease-out;
    }
    @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
    .modal-header { padding: 14px 16px; }
    .modal-body { padding: 14px 16px; }
    .modal-footer {
        padding: 12px 16px;
        position: sticky;
        bottom: 0;
        background: var(--bg-elevated);
        border-top: 1px solid var(--border);
    }
    .modal-footer .btn { flex: 1; }

    /* Tables: mobile card view (opt-in via .gmp-table-mobile-cards) */
    .gmp-table-mobile-cards thead { display: none; }
    .gmp-table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 10px;
        padding: 10px 12px;
        background: var(--bg-elevated);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
    }
    .gmp-table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        padding: 5px 0;
        border: none !important;
        text-align: right;
    }
    .gmp-table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-size: 10px;
        color: var(--text-tertiary);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        font-weight: 500;
        flex-shrink: 0;
        text-align: left;
    }
    .gmp-table-mobile-cards tbody td[data-label=""]::before { display: none; }
    .gmp-table-mobile-cards tbody td:first-child { border-top: none !important; }

    /* Normal tables: smaller padding */
    .gmp-table { font-size: var(--fs-sm); }
    .gmp-table thead th, .gmp-table tbody td { padding: 8px 8px; }

    /* Horizontal scroll hint - gradient po prawej + cień */
    .overflow-x-auto {
        position: relative;
        -webkit-overflow-scrolling: touch;
    }
    .overflow-x-auto::-webkit-scrollbar { height: 4px; }
    .overflow-x-auto::-webkit-scrollbar-thumb { background: var(--border-hover); }

    /* Sticky row-open column - disable on mobile (zajmuje miejsce) */
    .gmp-table th.row-open,
    .gmp-table td.row-open {
        position: static !important;
        box-shadow: none !important;
    }

    /* Hero KPI cards (dashboard, receivables) */
    .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .kpi { padding: 14px 14px !important; }
    .kpi-value { font-size: 22px !important; }
    .kpi-icon { top: 12px !important; right: 12px !important; width: 28px !important; height: 28px !important; font-size: 14px !important; }

    /* Today bar */
    .today-bar { grid-template-columns: repeat(2, 1fr) !important; }
    .today-bar > div { padding: 12px !important; gap: 10px !important; }
    .today-bar > div:nth-child(2n) { border-right: none !important; }
    .today-bar > div:nth-child(n+3) { border-top: 1px solid var(--border); }
    .today-bar .num { font-size: 18px !important; }
    .today-bar .icon-box { width: 32px !important; height: 32px !important; font-size: 15px !important; }

    /* Section headers */
    .section-h {
        margin: 20px 0 10px !important;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 4px;
    }

    /* Card headers */
    .card-header { padding: 10px 12px; font-size: var(--fs-sm); }

    /* Filter bars: full width inputs */
    .filter-input,
    input.filter-input,
    select.filter-input {
        width: 100% !important;
        min-height: 40px;
        font-size: 16px; /* zapobiega zoom iOS na focus */
    }
    /* Override any inline style="width: Xpx" for filters on mobile */
    [class*="filter-"][style*="width:"] {
        width: 100% !important;
    }

    /* Filter grids: wymuś 1 kolumnę */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    /* Page header actions: stack */
    .page-header > div.flex {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }
    .page-header > div.flex > * {
        flex: 1;
        min-width: auto;
    }

    /* Saved views bar */
    .sv-bar { padding: 8px 10px !important; gap: 6px !important; }
    .sv-chip { padding: 6px 12px !important; min-height: 32px; }
    .sv-add { margin-left: 0 !important; width: 100%; justify-content: center; }

    /* Tab buttons (tabs preset) */
    .tabs {
        overflow-x: auto;
        scrollbar-width: none;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { white-space: nowrap; flex-shrink: 0; }

    /* Composer */
    .composer-tabs { overflow-x: auto; padding: 6px 6px 0 !important; flex-wrap: nowrap; }
    .composer-tab { white-space: nowrap; flex-shrink: 0; }

    /* Dropdowns (tags, templates, bulk actions picker) - bottom sheet */
    .tag-picker,
    .tpl-picker,
    .dropdown {
        position: fixed !important;
        left: 8px !important;
        right: 8px !important;
        bottom: 8px !important;
        top: auto !important;
        width: auto !important;
        max-width: none !important;
        max-height: 60vh !important;
        overflow-y: auto !important;
        z-index: 100;
    }
    .tag-options,
    .tpl-options { max-height: 45vh !important; }

    /* Touch targets w inline-edit, tag-color, rating */
    .inline-edit-cancel { width: 28px; height: 28px; }
    .tag-color { width: 28px !important; height: 28px !important; }
    .work-action { width: 38px !important; height: 38px !important; }

    /* Stepper (w lead.html) - stack */
    .stepper {
        grid-template-columns: 1fr !important;
        gap: 2px !important;
    }
    .stepper .step-arrow,
    .stepper .step-arrow-col { display: none !important; }
    .stepper .step {
        flex-direction: row;
        text-align: left;
        padding: 10px 12px !important;
        justify-content: flex-start;
        gap: 10px;
    }
    .stepper .step .step-ic { width: 32px; height: 32px; }
    .stepper .step-dq { border-left: none !important; border-top: 1px dashed var(--border); }

    /* Notification drawer - right side, but don't exceed viewport */
    .notif-drawer { top: 60px !important; right: 8px !important; left: 8px !important; width: auto !important; }

    /* FAB */
    .gs-fab { bottom: 16px !important; right: 16px !important; width: 52px !important; height: 52px !important; }

    /* Case detail: sticky header adjustments */
    .case-header {
        margin: -16px -16px 0 !important;
        padding: 12px 16px !important;
    }
    .case-tabs { margin: 12px -16px 0 !important; padding: 0 16px !important; }

    /* Grid patterns - wymuś 1-kolumnowe */
    .grid.md\:grid-cols-2,
    .grid.md\:grid-cols-3,
    .grid.md\:grid-cols-4,
    .grid.md\:grid-cols-6,
    .grid.lg\:grid-cols-2,
    .grid.lg\:grid-cols-3,
    .grid.lg\:grid-cols-4,
    .grid.lg\:grid-cols-5,
    .grid.xl\:grid-cols-3,
    .grid.xl\:grid-cols-4,
    .grid.xl\:grid-cols-6 {
        grid-template-columns: 1fr !important;
    }
    /* Pozwól 2 kolumny tam gdzie ma sens (KPI) */
    .grid.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }

    /* Avoid iOS Safari scroll bounce on inputs */
    input, select, textarea { font-size: 16px; }
}
