/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1E3A5F;
    --primary-dark: #0F1C2E;
    --primary-light: #2C5282;
    --secondary-color: #3B82F6;
    --accent-color: #60A5FA;
    --danger-color: #DC2626;
    --warning-color: #F59E0B;
    --success-color: #10B981;
    --text-primary: #E5E7EB;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --bg-primary: #0F172A;
    --bg-secondary: #1E293B;
    --bg-tertiary: #334155;
    --bg-elevated: #243044;
    --border-color: #334155;
    --border-subtle: rgba(148, 163, 184, 0.12);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
    --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
}

body {
    font-family: var(--font-sans);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Login Page Styles */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(30, 58, 95, 0.35) 0%, transparent 45%),
        var(--bg-primary);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: var(--space-8);
}

.login-box {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-xl);
    text-align: center;
    border: 1px solid var(--border-color);
}

.logo {
    display: flex;
    justify-content: center;
    margin-bottom: var(--space-6);
}

.logo svg,
.login-logo {
    width: 180px;
    height: 180px;
    display: block;
}

.logo img {
    width: min(100%, 280px);
    height: auto;
    object-fit: contain;
    background: transparent;
}

.login-box h1 {
    font-size: var(--text-2xl);
    color: var(--accent-color);
    margin-bottom: var(--space-2);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-8);
}

.form-group {
    margin-bottom: var(--space-6);
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
    font-weight: 500;
    font-size: var(--text-sm);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-group small,
.form-hint {
    display: block;
    margin-top: var(--space-2);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.error-message {
    background-color: rgba(220, 38, 38, 0.2);
    color: #FCA5A5;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.btn-primary {
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: var(--secondary-color);
    color: white;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

.btn-primary:hover {
    background: #2563EB;
}

.btn-primary:active {
    background: #1D4ED8;
}

.btn-secondary {
    padding: 0.875rem 1.5rem;
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-secondary:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.login-footer {
    margin-top: var(--space-8);
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-color);
}

.login-footer p {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* Dashboard Styles */
.dashboard-page {
    background-color: var(--bg-primary);
}

.dashboard-container {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

/* Sidebar — vertical left rail */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: linear-gradient(180deg, #152238 0%, var(--bg-primary) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 100;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: var(--space-6) var(--space-5) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-3);
}

.logo-small {
    display: flex;
    justify-content: center;
}

.logo-small svg {
    width: 48px;
    height: 48px;
}

.logo-small img {
    object-fit: contain;
    background: transparent;
    mix-blend-mode: normal;
}

.sidebar-header h2 {
    font-size: var(--text-base);
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4) var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.7rem 0.85rem;
    color: rgba(255, 255, 255, 0.72);
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    white-space: nowrap;
    font-size: var(--text-sm);
    font-weight: 500;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: white;
}

.nav-item.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: white;
    border-left-color: var(--secondary-color);
}

.nav-item svg {
    flex-shrink: 0;
}

.toggle-menu-btn {
    display: none !important;
}

.sidebar-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.sidebar-user .user-avatar {
    width: 36px;
    height: 36px;
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.sidebar-user-meta {
    min-width: 0;
    text-align: left;
}

.sidebar-user-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-role {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: 100%;
    padding: 0.65rem 1rem;
    background-color: rgba(255, 255, 255, 0.06);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: var(--font-sans);
    white-space: nowrap;
}

.btn-logout:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

/* Main Content */
.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-8) 2.5rem;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-8);
    gap: var(--space-4);
}

.content-header h1 {
    font-size: var(--text-2xl);
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-name {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: var(--text-sm);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--text-base);
    border: 1px solid var(--border-color);
}

/* Content Sections */
.content-section {
    display: none;
}

.content-section.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
    gap: var(--space-4);
    flex-wrap: wrap;
}

.section-header h2 {
    font-size: var(--text-xl);
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.section-spacer {
    margin-top: var(--space-8);
}

/* Card */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    animation: fadeIn 0.3s ease;
}

.card-compact {
    padding: 1.5rem;
}

.card-compact .form-group label {
    font-size: var(--text-sm);
    margin-bottom: 0.4rem;
}

.card-compact .form-group input,
.card-compact .form-group select,
.card-compact .form-group textarea {
    padding: 0.6rem 0.8rem;
    font-size: var(--text-sm);
}

.card-compact .form-row {
    gap: 1.2rem;
    margin-bottom: 1.2rem;
}

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

.card-compact .btn-primary,
.card-compact .btn-secondary {
    padding: 0.7rem 1.2rem;
    font-size: var(--text-sm);
}

.card-title {
    margin-bottom: var(--space-4);
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-weight: 600;
}

.card-title.tight {
    margin-bottom: 0.25rem;
}

.card-title-lg {
    margin-bottom: var(--space-6);
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-weight: 600;
}

.card-spaced {
    margin-bottom: var(--space-8);
}

.card-spaced-top {
    margin-top: var(--space-8);
}

.muted-text {
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
}

.muted-text.no-margin {
    margin: 0;
}

.muted-inline {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* Form Styles */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
    margin-bottom: var(--space-6);
}

.form-row.spaced-top {
    margin-top: var(--space-8);
}

.form-span-full {
    grid-column: 1 / -1;
}

.form-group.relative {
    position: relative;
    overflow: visible;
}

.radio-group {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-2);
    flex-wrap: wrap;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.radio-option input,
.checkbox-inline input {
    width: auto;
    cursor: pointer;
    accent-color: var(--secondary-color);
}

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.input-uppercase {
    text-transform: uppercase;
}

/* ITP form: tip client + search */
.itp-form-top {
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
}

.client-type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    max-width: 420px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.3rem;
}

.client-type-option {
    position: relative;
    cursor: pointer;
    margin: 0;
}

.client-type-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.client-type-option span {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 0.85rem;
    border-radius: 6px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.client-type-option:hover span {
    color: var(--text-primary);
}

.client-type-option input:checked + span {
    background: rgba(59, 130, 246, 0.2);
    color: #93C5FD;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.client-search-wrap {
    display: none;
    margin-top: var(--space-4);
    position: relative;
    z-index: 20;
}

.client-search-wrap.is-visible {
    display: block;
}

.client-search-box {
    position: relative;
}

.client-search-box input {
    width: 100%;
    padding: 0.8rem 1rem 0.8rem 2.65rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.client-search-box input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.client-search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 1;
}

.client-search-hint {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.itp-form-fields .form-row {
    margin-bottom: 1.15rem;
}

.itp-form-fields .form-actions {
    margin-top: var(--space-5);
}

.form-actions {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-8);
    flex-wrap: wrap;
}

.form-actions .btn-primary {
    width: auto;
}

.btn-auto {
    width: auto;
}

.hidden {
    display: none !important;
}

.inline-actions {
    display: flex;
    gap: var(--space-4);
    align-items: center;
    flex-wrap: wrap;
}

/* Clienti section */
.clienti-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}

.clienti-toolbar-left h2 {
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin: 0;
}

.clienti-summary {
    margin: 0.25rem 0 0;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.clienti-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    flex: 1 1 420px;
    justify-content: flex-end;
}

.clienti-toolbar-right .search-box {
    flex: 1 1 200px;
    max-width: 280px;
    min-width: 160px;
}

.clienti-filters {
    display: inline-flex;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.clienti-filter-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    font-size: var(--text-xs);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.clienti-filter-btn + .clienti-filter-btn {
    border-left: 1px solid var(--border-color);
}

.clienti-filter-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.clienti-filter-btn.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-color);
}

.client-panel {
    animation: fadeIn 0.25s ease;
}

.client-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.client-form-header .card-title {
    margin-bottom: 0;
}

.table-empty {
    text-align: center !important;
    padding: 2.5rem 1rem !important;
    color: var(--text-secondary) !important;
}

.cell-strong {
    font-weight: 500;
    color: var(--text-primary);
}

.view-only-label {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* Client autocomplete */
#clientSuggestions,
.client-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.suggestion-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: rgba(59, 130, 246, 0.12);
}

.suggestion-item strong {
    color: var(--text-primary);
    font-weight: 600;
}

.suggestion-item small {
    color: var(--text-secondary);
    display: block;
    margin-top: 0.15rem;
}

.suggestion-status {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.suggestion-status.is-error {
    color: #FCA5A5;
}

/* Search Box */
.search-box {
    position: relative;
    flex: 1 1 220px;
    max-width: 360px;
    min-width: 180px;
}

.search-box input {
    width: 100%;
    padding: 0.7rem 1rem 0.7rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.search-box svg {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

/* Table Styles */
.table-container {
    overflow-x: auto;
    max-height: min(70vh, 720px);
    border-radius: var(--radius-md);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background-color: var(--bg-tertiary);
}

th {
    padding: 0.85rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    font-size: var(--text-sm);
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--bg-tertiary);
    white-space: nowrap;
}

td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

tbody tr {
    transition: background-color 0.15s ease;
}

tbody tr:hover {
    background-color: rgba(51, 65, 85, 0.45);
}

td:last-child {
    white-space: nowrap;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.28rem 0.7rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    max-width: none;
}

.status-valid {
    background-color: rgba(16, 185, 129, 0.18);
    color: #34D399;
    border: 1px solid rgba(16, 185, 129, 0.35);
}

.status-expiring {
    background-color: rgba(245, 158, 11, 0.18);
    color: #FBBF24;
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.status-expired {
    background-color: rgba(220, 38, 38, 0.18);
    color: #FCA5A5;
    border: 1px solid rgba(220, 38, 38, 0.35);
}

.role-badge {
    margin-left: var(--space-2);
}

.btn-icon.renew:hover {
    color: #34D399;
}

.btn-icon.call {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon.call:hover {
    color: #60A5FA;
}

.btn-icon:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Renew ITP modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(2, 6, 23, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-overlay.hidden,
.modal-overlay[hidden] {
    display: none !important;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    max-height: min(90vh, 640px);
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.4rem 1.5rem;
    box-shadow: var(--shadow-xl);
    animation: fadeIn 0.2s ease;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: 0.5rem;
}

.modal-header h3 {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.modal-card .form-group {
    margin-bottom: 1rem;
}

.modal-card .form-actions {
    margin-top: 1.25rem;
}

.modal-card .form-actions .btn-primary,
.modal-card .form-actions .btn-secondary {
    width: auto;
}

.renew-expiry-display {
    padding: 0.65rem 0.85rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-weight: 600;
    font-size: var(--text-base);
    min-height: 2.75rem;
    display: flex;
    align-items: center;
}

.renew-expiry-display.is-empty {
    color: var(--text-secondary);
    font-weight: 400;
}

.modal-card input[type="date"],
.modal-card select {
    color-scheme: dark;
    color: var(--text-primary);
    -webkit-appearance: none;
    appearance: none;
}

.modal-card input[type="date"]::-webkit-date-and-time-value {
    color: var(--text-primary);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: nowrap;
}

.btn-icon {
    padding: 0.55rem;
    min-width: 40px;
    min-height: 40px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s ease, color 0.15s ease;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-icon svg {
    pointer-events: none;
    flex-shrink: 0;
}

.btn-icon:hover {
    background-color: var(--bg-tertiary);
    color: var(--secondary-color);
}

.btn-icon.delete:hover {
    color: var(--danger-color);
}

/* DateTime Display */
.datetime-display {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.1rem;
}

.date-text {
    color: rgba(255, 255, 255, 0.7);
    font-size: var(--text-xs);
}

.time-text {
    color: var(--accent-color);
    font-size: var(--text-sm);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    border-color: rgba(59, 130, 246, 0.35);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue { background: rgba(59, 130, 246, 0.2); }
.stat-icon.green { background: rgba(16, 185, 129, 0.2); }
.stat-icon.amber { background: rgba(245, 158, 11, 0.2); }
.stat-icon.violet { background: rgba(139, 92, 246, 0.2); }
.stat-icon.lime { background: rgba(34, 197, 94, 0.2); }
.stat-icon.red { background: rgba(239, 68, 68, 0.2); }

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-label {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: 0.15rem;
}

.stat-value {
    color: var(--text-primary);
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

/* Charts */
.chart-container {
    min-height: 250px;
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--bg-primary);
    border-radius: var(--radius-md);
}

.chart-bar {
    flex: 1;
    background: linear-gradient(180deg, #3B82F6 0%, #2563EB 100%);
    border-radius: 4px 4px 0 0;
    min-height: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    transition: background 0.2s ease, transform 0.2s ease;
    cursor: pointer;
}

.chart-bar:hover {
    background: linear-gradient(180deg, #60A5FA 0%, #3B82F6 100%);
    transform: scaleY(1.04);
}

.bar-value {
    color: white;
    font-size: var(--text-xs);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.bar-label {
    position: absolute;
    bottom: -25px;
    color: var(--text-secondary);
    font-size: var(--text-xs);
}

/* SMS Preview & Info blocks */
.sms-preview {
    background: var(--bg-primary);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    white-space: pre-wrap;
}

.sms-meta-block {
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-color);
}

.sms-meta-line {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: 0.35rem;
}

.sms-info-box {
    background: rgba(59, 130, 246, 0.1);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid rgba(59, 130, 246, 0.3);
    margin-top: var(--space-4);
}

.sms-info-box p {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-bottom: var(--space-2);
}

.sms-info-box strong {
    color: var(--text-primary);
}

.sms-info-box ul {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    padding-left: 1.5rem;
}

.sms-info-box li + li {
    margin-top: 0.35rem;
}

.sms-info-box code {
    font-size: 0.8em;
    background: rgba(0, 0, 0, 0.25);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

/* SMS Log */
.sms-log-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.sms-log-summary {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.sms-log-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.sms-log-search {
    min-width: 220px;
    max-width: 280px;
}

.sms-log-search input {
    padding-right: 2.5rem;
}

.sms-log-filters {
    display: inline-flex;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.sms-filter-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem 0.85rem;
    font-size: var(--text-sm);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sms-filter-btn + .sms-filter-btn {
    border-left: 1px solid var(--border-color);
}

.sms-filter-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sms-filter-btn.active {
    background: rgba(16, 185, 129, 0.15);
    color: #34D399;
}

.btn-refresh-sms {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    font-size: var(--text-sm);
}

.sms-log-table-wrap {
    max-height: 480px;
    overflow: auto;
}

#smsLogTable th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--bg-tertiary);
}

#smsLogTable td {
    vertical-align: top;
    font-size: var(--text-sm);
}

#smsLogTable .sms-log-date {
    white-space: nowrap;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

#smsLogTable .sms-log-name {
    color: var(--text-primary);
    font-weight: 500;
}

#smsLogTable .sms-log-meta {
    display: block;
    margin-top: 0.2rem;
    color: var(--text-secondary);
    font-size: var(--text-xs);
}

#smsLogTable .sms-log-phone {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.sms-message-cell {
    max-width: 320px;
}

.sms-message-preview {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-wrap;
    line-height: 1.35;
    color: var(--text-secondary);
}

.sms-message-preview.is-expanded {
    display: block;
    -webkit-line-clamp: unset;
}

.sms-message-toggle {
    margin-top: 0.35rem;
    padding: 0;
    border: none;
    background: none;
    color: #34D399;
    font-size: var(--text-xs);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
}

.sms-message-toggle:hover {
    text-decoration: underline;
}

.sms-log-error {
    display: block;
    margin-top: 0.35rem;
    color: #FCA5A5;
    font-size: var(--text-xs);
    line-height: 1.3;
    max-width: 180px;
}

.sms-log-empty {
    text-align: center !important;
    padding: 2.5rem 1rem !important;
    color: var(--text-secondary) !important;
}

.status-sms-ok {
    background-color: rgba(16, 185, 129, 0.2);
    color: #34D399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-sms-fail {
    background-color: rgba(220, 38, 38, 0.2);
    color: #FCA5A5;
    border: 1px solid rgba(220, 38, 38, 0.3);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* ===== Responsive ===== */

/* Wide desktop: 3-col forms */
@media (min-width: 1280px) {
    .form-row {
        grid-template-columns: repeat(3, 1fr);
    }

    .form-row.form-row-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Tablet / mid: icon-only sidebar */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: var(--sidebar-collapsed);
    }

    .sidebar-header {
        padding: var(--space-4) var(--space-2);
    }

    .sidebar-header h2,
    .datetime-display,
    .nav-item span,
    .btn-logout span,
    .sidebar-user-meta {
        display: none;
    }

    .logo-small svg {
        width: 36px;
        height: 36px;
    }

    .nav-item {
        justify-content: center;
        padding: 0.75rem;
        border-left-width: 0;
        border-radius: var(--radius-md);
        position: relative;
    }

    .nav-item.active {
        background-color: rgba(59, 130, 246, 0.2);
    }

    .nav-item.active::before {
        content: '';
        position: absolute;
        left: 0;
        top: 20%;
        bottom: 20%;
        width: 3px;
        background: var(--secondary-color);
        border-radius: 0 2px 2px 0;
    }

    .sidebar-footer {
        padding: var(--space-3) var(--space-2);
        align-items: center;
    }

    .sidebar-user {
        justify-content: center;
    }

    .btn-logout {
        padding: 0.65rem;
    }

    .main-content {
        padding: var(--space-6) var(--space-5);
    }

    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-container {
        min-height: 200px;
    }

    .content-header .user-info .user-name,
    .content-header .role-badge {
        display: none;
    }
}

/* Mobile: top bar */
@media (max-width: 768px) {
    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: sticky;
        top: 0;
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        background: linear-gradient(90deg, #152238 0%, var(--bg-primary) 100%);
    }

    .sidebar-header {
        flex-direction: row;
        flex: 0 0 auto;
        padding: 0.5rem 0.75rem;
        border-bottom: none;
        gap: var(--space-2);
        text-align: left;
    }

    .logo-small svg {
        width: 36px;
        height: 36px;
    }

    .sidebar-header h2,
    .datetime-display,
    .sidebar-user {
        display: none;
    }

    .sidebar-nav {
        flex: 1 1 auto;
        flex-direction: row;
        align-items: center;
        padding: 0.35rem 0.25rem;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.1rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        padding: 0.5rem 0.65rem;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 0;
        flex-shrink: 0;
    }

    .nav-item span {
        display: none;
    }

    .nav-item.active {
        border-left: none;
        border-bottom-color: var(--secondary-color);
        background: transparent;
    }

    .sidebar-footer {
        flex: 0 0 auto;
        margin-top: 0;
        padding: 0.5rem 0.75rem;
        border-top: none;
        border-left: 1px solid var(--border-subtle);
    }

    .btn-logout {
        width: auto;
        padding: 0.5rem 0.65rem;
    }

    .btn-logout span {
        display: none;
    }

    .main-content {
        padding: var(--space-4);
        max-width: 100%;
    }

    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        margin-bottom: var(--space-6);
    }

    .content-header h1 {
        font-size: var(--text-xl);
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .section-header h2 {
        font-size: var(--text-lg);
    }

    .search-box {
        max-width: none;
        width: 100%;
        flex: 1 1 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
    }

    .table-container {
        max-height: none;
    }

    table {
        min-width: 800px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 1.25rem;
    }

    .stat-value {
        font-size: 1.75rem;
    }

    .chart-container {
        min-height: 180px;
        padding: 0.75rem;
    }

    .bar-label {
        font-size: 0.65rem;
    }

    .card {
        padding: 1.25rem;
    }

    .card-compact {
        padding: 1rem;
    }
}

@media (max-width: 900px) {
    .sms-log-header {
        flex-direction: column;
        align-items: stretch;
    }

    .sms-log-toolbar {
        width: 100%;
    }

    .sms-log-search {
        flex: 1;
        min-width: 0;
        max-width: none;
        width: 100%;
    }

    .sms-message-cell {
        max-width: 220px;
    }

    .clienti-toolbar-right {
        flex: 1 1 100%;
        justify-content: stretch;
    }

    .clienti-toolbar-right .search-box {
        max-width: none;
        width: 100%;
        flex: 1 1 100%;
    }

    .clienti-filters {
        width: 100%;
        overflow-x: auto;
    }

    .client-type-toggle {
        max-width: none;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .login-container {
        padding: var(--space-4);
    }

    .login-box {
        padding: 1.75rem 1.25rem;
    }

    .logo svg,
    .login-logo {
        width: 150px;
        height: 150px;
    }

    .logo img {
        width: min(100%, 220px);
    }

    .main-content {
        padding: 0.75rem;
    }

    .content-header h1 {
        font-size: var(--text-lg);
    }

    .card {
        padding: 1rem;
        border-radius: var(--radius-md);
    }

    .stat-icon {
        width: 40px;
        height: 40px;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .chart-container {
        min-height: 150px;
        padding: 0.5rem;
        gap: 0.25rem;
    }

    th, td {
        padding: 0.65rem 0.5rem;
        font-size: var(--text-sm);
    }

    .status-badge {
        padding: 0.25rem 0.5rem;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .btn-logout,
    .form-actions,
    .action-buttons,
    .search-box {
        display: none !important;
    }

    .main-content {
        max-width: none;
        padding: 0;
    }

    .card {
        border: 1px solid #000;
        page-break-inside: avoid;
        animation: none;
    }

    table {
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}
