* {
    box-sizing: border-box;
}

:root {
    --primary: #60a5fa;
    --primary-hover: #3b82f6;
    --bg-dark: #09090b;
    --card-dark: #18181b;
    --header-dark: #09090b;
    --text-light: #fafafa;
    --text-dim: #a1a1aa;
    --border-dark: #27272a;
    --nav-width: 240px;
    --header-height: 56px;
    --transition: all 0.2s ease;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
}

body.modern-theme {
    background-color: var(--bg-dark) !important;
    color: var(--text-light) !important;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
}

/* Global Overrides for Dark Mode */
.modern-theme, 
.modern-theme body, 
.modern-theme .page-body, 
.modern-theme .right-data {
    background-color: var(--bg-dark) !important;
    color: var(--text-light) !important;
}

.modern-theme table, 
.modern-theme .accounts-table, 
.modern-theme .general-table,
.modern-theme .reports-table,
.modern-theme .reports-table-table,
.modern-theme .mooring-list-index,
.modern-theme .passdown-table {
    background: var(--card-dark) !important;
    border-color: var(--border-dark) !important;
    color: var(--text-light) !important;
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 8px 0 !important;
}

.modern-theme tr:nth-child(even) {
    background-color: rgba(255,255,255,0.02) !important;
}

.modern-theme tr:hover {
    background-color: rgba(255,255,255,0.05) !important;
}

.modern-theme th {
    background: #000 !important;
    color: var(--primary) !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    font-size: 0.7rem !important;
    letter-spacing: 0.05em !important;
    border-bottom: 2px solid var(--border-dark) !important;
    padding: 4px 10px !important;
    text-align: left !important;
}

.modern-theme td {
    padding: 4px 10px !important;
    border-bottom: 1px solid var(--border-dark) !important;
    color: var(--text-light) !important;
}

/* Status Circles */
.status-circle {
    display: inline-block !important;
    width: 12px !important;
    height: 12px !important;
    min-width: 12px !important;
    min-height: 12px !important;
    border-radius: 50% !important;
    margin-right: 5px !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    vertical-align: middle !important;
}

.status-green { background-color: #10b981 !important; }
.status-orange { background-color: #fd7e14 !important; }
.status-yellow { background-color: #f59e0b !important; }
.status-red { background-color: #ef4444 !important; }
.status-blue { background-color: #3b82f6 !important; }

.modern-theme .icon-img {
    height: 14px !important;
    width: auto !important;
}

.modern-theme .module, 
.modern-theme .edit-module, 
.modern-theme .d-module,
.modern-theme .stats-module {
    background: var(--card-dark) !important;
    border: 1px solid var(--border-dark) !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    margin-bottom: 12px !important;
    width: 100% !important;
    max-width: 100% !important;
}

.modern-theme .module-header, 
.modern-theme .edit-module-header, 
.modern-theme .d-module-header {
    background: rgba(255,255,255,0.03) !important;
    border-bottom: 1px solid var(--border-dark) !important;
    color: var(--primary) !important;
    padding: 4px 12px !important;
    font-weight: 700 !important;
    font-size: 0.8125rem !important;
    height: auto !important;
    line-height: normal !important;
}

.modern-theme .module-content, 
.modern-theme .edit-module-content, 
.modern-theme .d-module-content,
.modern-theme .d-data,
.modern-theme .content {
    padding: 8px 12px !important;
    background: transparent !important;
    color: var(--text-light) !important;
}

.modern-theme h1, .modern-theme h2, .modern-theme h3 {
    color: var(--text-light) !important;
}

.modern-theme a {
    color: white;
    text-decoration: none;
    transition: var(--transition);
}

.modern-theme a:hover {
    color: var(--primary-hover);
}

.modern-link {
    color: var(--primary) !important;
    text-decoration: none !important;
    font-weight: 500 !important;
}

.modern-link:hover {
    text-decoration: underline !important;
    color: var(--primary-hover) !important;
}

.modern-theme .response-header {
    width: 100% !important;
    border-radius: 8px !important;
    margin-bottom: 8px !important;
}

/* Layout Structure */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

.log-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 20px;
    align-items: start;
    width: 100%;
}

.weather-tide-row {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.weather-tide-row .module {
    flex: 1;
    margin-bottom: 0 !important;
}

.alert-box {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    color: #f87171;
}

.weather-card, .tide-card {
    background: rgba(255,255,255,0.02);
    padding: 10px 15px;
    padding-right: 45px; /* Space for icon */
    border-radius: 10px;
    border: 1px solid var(--border-dark);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative !important;
    min-height: 70px;
    max-width: 250px;
    overflow: hidden;
}

.weather-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    height: 32px;
    width: 32px;
    opacity: 0.9;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
}

.weather-card:hover, .tide-card:hover {
    background: rgba(255,255,255,0.04);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.tide-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.8rem;
    font-weight: bold;
    opacity: 0.2;
    user-select: none;
}

.tide-high {
    background: rgba(16, 185, 129, 0.05) !important;
}

.tide-low {
    background: rgba(59, 130, 246, 0.05) !important;
}

.tide-high .tide-icon {
    color: var(--success);
}

.tide-low .tide-icon {
    color: var(--info);
}

@media (max-width: 1400px) {
    .log-grid {
        grid-template-columns: 1fr;
    }
    .weather-tide-row {
        flex-direction: column;
    }
}

.nav-head.modern-theme {
    background: var(--header-dark);
    border-bottom: 1px solid var(--border-dark);
    padding: 0 24px;
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.nav-head-left {
    display: flex;
    align-items: center;
    min-width: 0;
}

.mobile-nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1100;
    margin-right: 15px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-toggle .bar {
    width: 100%;
    height: 2px;
    background-color: var(--text-light);
    border-radius: 10px;
    transition: var(--transition);
}

.nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 850;
    cursor: pointer;
}

.page-body.modern-theme {
    display: flex;
    margin-top: var(--header-height);
    flex: 1;
}

/* Modern Sidebar */
.left-bar.modern-theme {
    width: var(--nav-width);
    background: var(--header-dark);
    border-right: 1px solid var(--border-dark);
    height: calc(100vh - var(--header-height));
    position: fixed;
    left: 0;
    padding: 16px 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 900;
    transition: var(--transition);
}

.nav-item.modern-theme {
    padding: 10px 16px;
    margin: 2px 12px;
    border-radius: 6px;
    transition: var(--transition);
}

.nav-item.modern-theme:hover {
    background: rgba(255,255,255,0.05);
}

.nav-item.nav-active.modern-theme {
    background: var(--primary);
    color: white;
}

.nav-item a img, 
.nav-item a span {
    pointer-events: none;
}

.nav-item a {
    text-decoration: none;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 0.95rem;
    width: 100%;
}

.nav-item img {
    width: 14px;
    height: 14px;
    filter: brightness(0) invert(1);
    opacity: 0.7;
}

.nav-item.nav-active img {
    opacity: 1;
}

.sub-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0 8px 40px;
}

.sub-nav a {
    font-size: 0.9rem !important;
    color: var(--text-dim) !important;
    padding: 6px 12px;
    border-radius: 4px;
    transition: var(--transition);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sub-nav a::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: var(--transition);
}

.sub-nav a:hover::before, .sub-nav a.sub-active::before {
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary);
}

.sub-nav a.sub-active {
    color: white !important;
    background: rgba(255,255,255,0.05);
}

.sub-nav a:hover {
    color: white !important;
    background: rgba(255,255,255,0.08);
}

/* Top Bar Components */
.nav-head-header.modern-theme a {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-light);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.nav-head-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.account.modern-theme {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.account-details {
    display: flex;
    flex-direction: column;
}

.account-name {
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.25;
}

.account-rank {
    color: var(--text-dim);
    font-size: 0.75rem;
    line-height: 1;
}


.profile-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--card-dark);
    border: 2px solid var(--border-dark);
}

/* Content Area */
.right-data.modern-theme {
    flex: 1;
    margin-left: var(--nav-width);
    padding: 4px 24px 24px 24px;
    min-width: 0;
}

/* Cards & Modules */
.modern-card, .module, .edit-module {
    background: var(--card-dark);
    border-radius: 12px;
    padding: 0;
    border: 1px solid var(--border-dark);
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    margin-bottom: 12px;
}

/* Accounts Page Specifics */
.accounts-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 20px;
    flex-wrap: wrap;
}

.accounts-legend {
    display: flex;
    gap: 24px;
    background: var(--card-dark);
    padding: 12px 20px;
    border-radius: 10px;
    border: 1px solid var(--border-dark);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--text-dim);
}

.legend-item img {
    width: 12px;
    height: 12px;
    opacity: 0.8;
}

.table-container {
    background: var(--card-dark);
    border-radius: 12px;
    border: 1px solid var(--border-dark);
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

/* Forms & Buttons */
.modern-btn, .common-button-large, .common-button-small {
    padding: 2px 8px !important;
    border-radius: 4px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    line-height: normal;
    height: 24px !important;
}

.modern-btn img, .modern-btn svg {
    width: 12px;
    height: 12px;
    filter: brightness(0) invert(1);
    flex-shrink: 0;
}

.common-button-yellow img, .common-button-yellow svg {
    filter: none !important;
}

.modern-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    filter: brightness(1.1);
}

.modern-btn:active {
    transform: translateY(0);
}

.common-button-blue { background: var(--primary); color: white; }
.common-button-blue:hover { background: var(--primary-hover); }

/* Notifications & Responses */
.response-header {
    padding: 12px 20px !important;
    border-radius: 8px !important;
    margin-bottom: 20px !important;
    font-weight: 600 !important;
    display: flex;
    align-items: center;
}

#response-header-success {
    background: rgba(16, 185, 129, 0.1) !important;
    border: 1px solid var(--success) !important;
    color: var(--success) !important;
}

#response-header-error {
    background: rgba(239, 68, 68, 0.1) !important;
    border: 1px solid var(--danger) !important;
    color: var(--danger) !important;
}

.common-button-green { background: var(--success); color: white; }
.common-button-red { background: var(--danger); color: white; }
.common-button-yellow { background: var(--warning); color: white; }
.common-button-orange { background: #f97316; color: white; }
.common-button-purple { background: #8b5cf6; color: white; }
.common-button-gray { background: #6b7280; color: white; }

.logout-btn {
    padding: 4px 12px !important;
    font-size: 0.75rem !important;
    text-decoration: none !important;
    height: 28px !important;
}

input[type="text"], 
input[type="date"], 
input[type="month"], 
input[type="number"], 
input[type="time"], 
input[type="email"], 
input[type="password"], 
textarea, 
select {
    background: var(--card-dark) !important;
    border: 1px solid var(--border-dark) !important;
    color: var(--text-light) !important;
    padding: 8px 12px !important;
    border-radius: 6px !important;
    font-size: 0.9rem !important;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23a1a1aa'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 12px !important;
    padding-right: 40px !important;
    transition: var(--transition);
}

select:hover {
    border-color: var(--text-dim) !important;
}

option {
    background: var(--card-dark);
    color: var(--text-light);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    outline: none;
}

/* Common Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 24px;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.header-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Form Layouts */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.block.full-width {
    grid-column: 1 / -1;
}

.modern-form .block {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modern-form .aLabel {
    width: auto !important;
    text-align: left !important;
    font-weight: 600 !important;
    font-size: 0.75rem !important;
    color: var(--text-dim) !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Dashboard Specifics */
#passdown-form {
    display: flex;
    flex-direction: row;
    gap: 12px;
    margin-bottom: 8px;
}

#passon-narrative {
    flex: 1;
    min-height: 40px;
    height: 40px;
    resize: vertical;
}

#passdown-submit {
    align-self: flex-start;
    background: var(--primary);
    color: white;
    border: none;
    height: 40px;
    padding: 0 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

#passdown-submit:hover {
    background: var(--primary-hover);
}

.passdown-table td#narrative {
    white-space: pre-wrap;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: var(--card-dark);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border-dark);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--card-dark);
    z-index: 10;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-light);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-section {
    padding: 24px;
    border-bottom: 1px solid var(--border-dark);
}

.modal-section h3 {
    margin: 0 0 16px 0;
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

.modal-footer {
    padding: 20px 24px;
    background: var(--card-dark);
    border-top: 1px solid var(--border-dark);
    display: flex;
    justify-content: flex-end;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

/* Login Page */
.login-box {
    background: var(--card-dark) !important;
    border: 1px solid var(--border-dark) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
    border-radius: 16px !important;
    padding: 40px !important;
    width: 100% !important;
    max-width: 400px !important;
    margin: 100px auto !important;
}

.login-input input {
    width: 100% !important;
    margin-bottom: 16px !important;
}

#submit[name="login-request"] {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}


/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* Responsive */
@media (max-width: 1024px) {
    :root { --nav-width: 80px; }
    .nav-item a span { display: none; }
    .nav-item { display: flex; justify-content: center; }
    .right-data.modern-theme { margin-left: var(--nav-width); }
}

@media (max-width: 1024px) and (min-width: 769px) {
    .sub-nav { display: none !important; }
}

@media (max-width: 768px) {
    .mobile-nav-toggle {
        display: flex;
    }
    
    .nav-item {
        display: block;
        padding: 10px 16px;
    }
    
    .nav-item a span {
        display: inline;
    }
    
    .nav-head.modern-theme {
        padding: 0 16px;
    }
    
    .nav-head-header.modern-theme {
        min-width: 0;
        flex: 1;
    }
    
    .nav-head-header.modern-theme a {
        font-size: 0.95rem;
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
        color: #fafafa;
        color: var(--text-light);
    }
    
    .account-rank, .account-details {
        display: none;
    }
    
    .logout-btn {
        padding: 4px 10px !important;
        font-size: 0.75rem !important;
    }
    
    .nav-head-right {
        gap: 12px;
    }
    
    .left-bar {
        transform: translateX(-100%);
        -webkit-transform: translateX(-100%);
        width: 260px; /* Slightly wider on mobile for better readability */
        height: calc(100vh - var(--header-height));
        top: var(--header-height);
    }
    
    body.mobile-nav-open .left-bar {
        transform: translateX(0);
        -webkit-transform: translateX(0);
    }
    
    body.mobile-nav-open .nav-overlay {
        display: block;
    }

    body.mobile-nav-open .mobile-nav-toggle .bar:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }
    body.mobile-nav-open .mobile-nav-toggle .bar:nth-child(2) {
        opacity: 0;
    }
    body.mobile-nav-open .mobile-nav-toggle .bar:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }
    
    .right-data.modern-theme {
        margin-left: 0 !important;
        padding: 12px !important;
    }
    
    .module-content, .edit-module-content {
        overflow-x: auto;
    }
    
    .log-grid {
        grid-template-columns: 1fr;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .header-actions .modern-btn {
        flex: 1;
        justify-content: center;
        padding: 8px;
    }

    .modal-box {
        width: 95%;
        margin: 10px;
    }
    
    .modal-header, .modal-section, .modal-footer {
        padding: 16px;
    }

    .sub-nav a {
        padding: 10px 12px !important;
        font-size: 0.95rem !important;
    }
}
